org.jomc.cli.commands
Class AbstractCommand

Package class diagram package AbstractCommand
java.lang.Object
  extended by org.jomc.cli.commands.AbstractCommand
All Implemented Interfaces:
Command
Direct Known Subclasses:
AbstractModletCommand

@Generated(value="org.jomc.tools.SourceFileProcessor 1.2.2",
           comments="See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2")
public abstract class AbstractCommand
extends Object
implements Command

JOMC CLI command implementation.

Identifier:
JOMC CLI Command
Name:
JOMC CLI Command
Specifications:
JOMC CLI Command @ 1.0
Abstract:
Yes
Final:
No
Stateless:
No

Version:
1.2.5
Author:
Christian Schulte 1.0

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jomc.cli.Command
Command.Listener
 
Field Summary
 
Fields inherited from interface org.jomc.cli.Command
STATUS_FAILURE, STATUS_SUCCESS
 
Constructor Summary
AbstractCommand()
          Creates a new AbstractCommand instance.
 
Method Summary
 int execute(CommandLine commandLine)
          Executes the command.
protected abstract  void executeCommand(CommandLine commandLine)
          Called by the execute method prior to the postExecuteCommand method.
 String getAbbreviatedName()
          Gets the abbreviated name of the command.
static Level getDefaultLogLevel()
          Gets the default log level events are logged at.
protected static String getExceptionMessage(Throwable t)
          Gets a message of a given throwable recursively.
 List<Command.Listener> getListeners()
          Gets the list of registered listeners.
 Level getLogLevel()
          Gets the log level of the instance.
 String getLongDescription(Locale locale)
          Gets the long description of the command.
 String getName()
          Gets the name of the command.
 Options getOptions()
          Gets the options of the command.
 String getShortDescription(Locale locale)
          Gets the short description of the command.
protected  boolean isLoggable(Level level)
          Checks if a message at a given level is provided to the listeners of the instance.
protected  void log(Level level, String message, Throwable throwable)
          Notifies registered listeners.
protected  void postExecuteCommand(CommandLine commandLine)
          Called by the execute method after the preExecuteCommand/executeCommand methods even if those methods threw an exception.
protected  void preExecuteCommand(CommandLine commandLine)
          Called by the execute method prior to the executeCommand method.
static void setDefaultLogLevel(Level value)
          Sets the default log level events are logged at.
 void setLogLevel(Level value)
          Sets the log level of the instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCommand

@Generated(value="org.jomc.tools.SourceFileProcessor 1.2.2",
           comments="See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2")
public AbstractCommand()
Creates a new AbstractCommand instance.

Method Detail

getListeners

public final List<Command.Listener> getListeners()
Gets the list of registered listeners.

This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the object. This is why there is no set method for the listeners property.

Specified by:
getListeners in interface Command
Returns:
The list of registered listeners.
See Also:
log(java.util.logging.Level, java.lang.String, java.lang.Throwable)

getLogLevel

public final Level getLogLevel()
Gets the log level of the instance.

Specified by:
getLogLevel in interface Command
Returns:
The log level of the instance.
See Also:
getDefaultLogLevel(), setLogLevel(java.util.logging.Level), isLoggable(java.util.logging.Level)

setLogLevel

public final void setLogLevel(Level value)
Sets the log level of the instance.

Specified by:
setLogLevel in interface Command
Parameters:
value - The new log level of the instance or null.
See Also:
getLogLevel(), isLoggable(java.util.logging.Level)

getName

public final String getName()
Description copied from interface: Command
Gets the name of the command.

Specified by:
getName in interface Command
Returns:
The name of the command.

getAbbreviatedName

public final String getAbbreviatedName()
Description copied from interface: Command
Gets the abbreviated name of the command.

Specified by:
getAbbreviatedName in interface Command
Returns:
The abbreviated name of the command.

getShortDescription

public final String getShortDescription(Locale locale)
Description copied from interface: Command
Gets the short description of the command.

Specified by:
getShortDescription in interface Command
Parameters:
locale - The locale of the short description to return.
Returns:
The short description of the command.

getLongDescription

public final String getLongDescription(Locale locale)
Description copied from interface: Command
Gets the long description of the command.

Specified by:
getLongDescription in interface Command
Parameters:
locale - The locale of the long description to return.
Returns:
The long description of the command.

execute

public final int execute(CommandLine commandLine)
Description copied from interface: Command
Executes the command.

Specified by:
execute in interface Command
Parameters:
commandLine - Command line to execute.
Returns:
The status code to report.
See Also:
Command.STATUS_SUCCESS, Command.STATUS_FAILURE

getDefaultLogLevel

public static Level getDefaultLogLevel()
Gets the default log level events are logged at.

The default log level is controlled by system property org.jomc.cli.commands.AbstractCommand.defaultLogLevel holding the log level to log events at by default. If that property is not set, the WARNING default is returned.

Returns:
The log level events are logged at by default.
See Also:
getLogLevel(), Level.parse(java.lang.String)

setDefaultLogLevel

public static void setDefaultLogLevel(Level value)
Sets the default log level events are logged at.

Parameters:
value - The new default level events are logged at or null.
See Also:
getDefaultLogLevel()

isLoggable

protected boolean isLoggable(Level level)
Checks if a message at a given level is provided to the listeners of the instance.

Parameters:
level - The level to test.
Returns:
true, if messages at level are provided to the listeners of the instance; false, if messages at level are not provided to the listeners of the instance.
Throws:
NullPointerException - if level is null.
See Also:
getLogLevel(), setLogLevel(java.util.logging.Level)

log

protected void log(Level level,
                   String message,
                   Throwable throwable)
Notifies registered listeners.

Parameters:
level - The level of the event.
message - The message of the event or null.
throwable - The throwable of the event null.
Throws:
NullPointerException - if level is null.
See Also:
getListeners(), isLoggable(java.util.logging.Level)

preExecuteCommand

protected void preExecuteCommand(CommandLine commandLine)
                          throws CommandExecutionException
Called by the execute method prior to the executeCommand method.

Parameters:
commandLine - The command line to execute.
Throws:
NullPointerException - if commandLine is null.
CommandExecutionException - if executing the command fails.
See Also:
execute(org.apache.commons.cli.CommandLine)

executeCommand

protected abstract void executeCommand(CommandLine commandLine)
                                throws CommandExecutionException
Called by the execute method prior to the postExecuteCommand method.

Parameters:
commandLine - The command line to execute.
Throws:
CommandExecutionException - if executing the command fails.
See Also:
execute(org.apache.commons.cli.CommandLine)

postExecuteCommand

protected void postExecuteCommand(CommandLine commandLine)
                           throws CommandExecutionException
Called by the execute method after the preExecuteCommand/executeCommand methods even if those methods threw an exception.

Parameters:
commandLine - The command line to execute.
Throws:
NullPointerException - if commandLine is null.
CommandExecutionException - if executing the command fails.
See Also:
execute(org.apache.commons.cli.CommandLine)

getExceptionMessage

protected static String getExceptionMessage(Throwable t)
Gets a message of a given throwable recursively.

Parameters:
t - The Throwable to get the message of or null.
Returns:
The message associated with t or null.

getOptions

@Generated(value="org.jomc.tools.SourceFileProcessor 1.2.2",
           comments="See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2")
public Options getOptions()
Gets the options of the command.

Options:

Specification Implementation

Specified by:
getOptions in interface Command
Returns:
The options of the command.


Copyright © 2005-2012 The JOMC Project. All Rights Reserved.Get JOMC at SourceForge.net. Fast, secure and Free Open Source software downloads
Please note that this documentation is maintained by non-native english speaking authors. As such, you may encounter phrases or wordings which seem imprecise or may even have a totally different meaning to native english speaking readers than what the individual author was trying to express. If you are a native english speaking reader and find any such phrases or wordings we kindly ask you to send an email to the corresponding author and help us improve this documentation in order to avoid misunderstandings. You will find the authors' email addresses at the top of each class. Please accept our apologies for any inconvenience caused.