The first step in adding the new business logic is to create a new implementation class that extends the original implementation class. In this example, you would create a new ModifiedControllerCmdImpl class that extends the ExistingControllerCmdImpl class. The new implementation class should implement the original interface (ExistingControllerCmd).
In the new implementation class you must create a new performExecute method to override the performExecute of the existing command. Within the newperformExecute method, there are two ways in which you can insert your new business logic: you can either include the code directly in the controller command, or you can create a new task command to perform the new business logic. If you create a new task command then you must instantiate the new task command object from within the controller command.
The following code snippet demonstrates how to add new business logic to the beginning and end of an existing controller command by including the logic directly in the controller command:
public class ModifiedControllerCmdImpl extends ExistingControllerCmdImpl
implements ExistingControllerCmd
{
public void performExecute ()
throws com.ibm.commerce.exception.ECException
{
/* Insert new business logic that must be
executed before the original command.
*/
// Execute the original command logic.
super.performExecute();
/* Insert new business logic that must be
executed after the original command.
*/
}
}
The following code snippet demonstrates how to add new business logic to the beginning of an existing controller command by instantiating a new task command from within the controller command. In addition, you would also create the new task command interface and implementation class and register the task command in the command registry.
// Import the package with the CommandFactory
import com.ibm.commerce.command.*;
public class ModifiedControllerCmdImpl extends ExistingControllerCmdImpl
implements ExistingControllerCmd
{
public void performExecute ()
throws com.ibm.commerce.exception.ECException
{
MyNewTaskCmd cmd = null;
cmd = (MyNewTaskCmd) CommandFactory.createCommand(
"com.mycompany.mycommands.MyNewTaskCommand",
getStoreId());
/*
Set task command's input parameters, call its
execute method and retrieve output
parameters, as required.
*/
super.performExecute();
}
}
Regardless of whether you include the new business logic in the controller command, or create a task command to perform the logic, you must also update the CMDREG table in the WebSphere Commerce command registry to associate the new controller command implementation class with the existing controller command interface. The following SQL statement shows an example update:
update CMDREG
set CLASSNAME='ModifiedControllerCmdImpl'
where INTERFACENAME='ExistingControllerCmd';
No comments:
Post a Comment