Task command programming model

A new task command should extend the abstract task command class com.ibm.commerce.command.TaskCommandImpl and implement an interface that extends the com.ibm.commerce.command.TaskCommand interface.

The following diagram illustrates the relationship between the implementation class and interface of a new task command with the existing abstract implementation class and interface. The abstract class and interface are both found in the com.ibm.commerce.command package.

In Java, the new MyTaskCmdImpl task command will then be defined as follows:

All the input and output properties for the task command must be defined in the command interface, for example MyTaskCmd. The caller programs to the task command interface, rather than the task command implementation class. This enables you to have multiple implementations of the task command (one for each store), without the caller being concerned about which implementation class to call.

All the methods defined in the interface must be implemented in the implementation class. Since the command context should be set by the caller (a controller command), the task command does not need to set the command context. The task command can, however, obtain additional session information using the command context.

In addition to implementing the methods defined in the task command interface, you should override the performExecute method from the com.ibm.commerce.command.TaskCommandImpl class.

The performExecute method contains the business logic for the particular unit of work that the task command performs. It should invoke the performExecute method of the task command's superclass, before performing any business logic. The following code snippet shows an example performExecute method for a task command.

The runtime framework calls the getResources method of the controller command to determine which protectable resources the command will access. It may be the case that a task command is executed during the scope of a controller command and it attempts to access resources that were not returned by the getResources method of the controller command. If this is the case, the task command itself can implement a getResources method to ensure that access control is provided for protectable resources.

Note that by default, getResources returns null for a task command and resource-level access control checking is not performed. Therefore, we must override this if the task command accesses protectable resources.


Related concepts
WebSphere Commerce functional overview
Command types


Related tasks
Customizing existing task commands