If a client needs to set the target of the command by name, it
can use the setCommandTargetName method for the command.
Identifying a target with CommandTargetName
This example compares with the example in
Using a command as follows:
- Both explicitly set the command target in the constructor to null.
- Both use the setCheckingAccount method to indicate the account on which
the command should operate.
- This example sets the target name explicitly by using the setCommandTargetName
method. When the default target policy traverses its choices, it finds a null
for the first choice and a name for the second.
{
...
CheckingAccount checkingAccount
....
try {
ModifyCheckingAccountCmd cmd =
new ModifyCheckingAccountCmdImpl(null, 1000);
cmd.setCheckingAccount(checkingAccount);
cmd.setCommandTargetName("com.ibm.sfc.cmd.test.CheckingAccountBean");
cmd.execute();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
...
}