Example: Implementing methods from the TargetableCommand interface

The TargetableCommand interface declares one method, performExecute, that application programmer must implement.

Methods from the TargetableCommand interface in the ModifyCheckingAccountCmdImpl class

The following code example shows the implementations for the ModifyCheckingAccountCmd command. The implementation of the performExecute method is as follows:
  • Saves the current balance (so the command can be undone by a compensator command)
  • Calculates the new balance
  • Sets the current balance to the new balance
  • Ensures that the hasOutputProperties method returns true so that the values are returned to the client
In addition, the ModifyCheckingAccountCmdImpl class overrides the default implementation of the setOutputProperties method.
...
public class ModifyCheckingAccountCmdImpl extends TargetableCommandImpl
implements ModifyCheckingAccountCmd
{
...
// Method from the TargetableCommand interface
public void performExecute() throws Exception {
CheckingAccount checkingAccount = getCheckingAccount();
oldBalance = checkingAccount.getBalance();
balance = oldBalance+amount;
checkingAccount.setBalance(balance);
setHasOutputProperties(true);
}
public void setOutputProperties(TargetableCommand fromCommand) {
try {
if (fromCommand != null) {
ModifyCheckingAccountCmd modifyCheckingAccountCmd =
(ModifyCheckingAccountCmd) fromCommand;
this.oldBalance = modifyCheckingAccountCmd.getOldBalance();
this.balance = modifyCheckingAccountCmd.getBalance();
this.checkingAccount =
modifyCheckingAccountCmd.getCheckingAccount();
this.amount = modifyCheckingAccountCmd.getAmount();
}
}
catch (Exception ex) {
System.out.println("Error in setOutputProperties.");
}
}
...
}



Related tasks
Implementing command interfaces
Reference topic Reference topic    

Terms and conditions for information centers | Feedback

Last updatedLast updated: Aug 30, 2013 10:47:11 PM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=pix&product=was-nd-iseries&topic=rcmd_implmethtcint
File name: rcmd_implmethtcint.html