public abstract class IfsCommand extends Object implements Command
Command
Constructor and Description |
---|
IfsCommand()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
CommandContext |
createCommandContext()
Create a default implementation of the command context object.
|
protected void |
execute(CommandContext context)
This method is run between
preExecute and
postExecute if preExecute does not throw an
exception. |
void |
populateNestedCommands(CommandInvoker commandInvoker)
Populate all the needed nested commands.
|
protected void |
postExecute(CommandContext context,
IfsException e)
This method is always run after
execute . |
protected void |
preExecute(CommandContext context)
This method is always run before the
execute method. |
void |
run(CommandContext context)
Run the command.
|
public final void run(CommandContext context) throws IfsException
run
in interface Command
context
- the command context.IfsException
- if exception is thrown in the execution.CommandContext
public void populateNestedCommands(CommandInvoker commandInvoker) throws IfsException
CommandInvoker
is not guaranteed to exist for the lifetime of
the command. Therefore, the command should not keep a reference to the
command invoker and it should acquire all the references to the needed
commands in this call-back method.
populateNestedCommands
in interface Command
commandInvoker
- The CommandInvoker
object that can be
used to acquire references to the needed
sub-commands.IfsException
- If there is any exception thrown.CommandInvoker
public CommandContext createCommandContext() throws IfsException
createCommandContext
in interface Command
CommandContext
.IfsException
CommandContext
protected void preExecute(CommandContext context) throws IfsException
execute
method.
This is the extension point of the command for setup code. Subclass could overwrite this method for any setup code. The default implementation does nothing.
context
- the command context.IfsException
protected void execute(CommandContext context) throws IfsException
preExecute
and
postExecute
if preExecute
does not throw an
exception. In which case niether execute nore postexecute is called.
This is the method where the subclasses should overwrite to provide functionality for the command. The default implementation throws an IfsException (errorcode 68025).
context
- the command context.IfsException
- if execution failsprotected void postExecute(CommandContext context, IfsException e) throws IfsException
execute
.
This is the extension point of the command for cleanup code. Subclass should overwrite this method for any cleanup code. The default implementation rethrows the exception if not null.
context
- the command context.e
- the exception if one occured.IfsException
Copyright © 2023. All rights reserved.