Setting the command target

The ModifyCheckingAccountImpl class provides two command constructors. One of them takes a command target as an argument and implicitly uses the default target policy to locate the target. The constructor passes a null target, so that the default target policy traverses its choices and eventually finds the default target name, LocalTarget.

Identifying a target with CommandTarget

If you use this default implementation, the command determines the target by looking through an ordered sequence of four options:
  • The CommandTarget value
  • The CommandTargetName value
  • A registered mapping of a target for a specific command
  • A defined default target
If the command finds no target, it returns null.
This example uses the same constructor to set the target explicitly. This example differs from the example in Using a command as follows:
  • The command target is set to the checking account rather than null. The default target policy starts to traverse its choices and finds the target in the first place it looks.
  • It does not have to call the setCheckingAccount method to indicate the account on which the command should operate; the constructor uses the target variable as both the target and the account.
{
...
CheckingAccount checkingAccount
....
try {
ModifyCheckingAccountCmd cmd =
new ModifyCheckingAccountCmdImpl(checkingAccount, 1000);
cmd.execute();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
...
}



Related concepts
Targets and target policies
Related tasks
Using a command
Reference topic    

Terms of Use | Feedback

Last updated: Feb 19, 2011 5:25:36 AM CST
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=v610web&product=was-nd-mp&topic=rcmd_setcmdtarg
File name: rcmd_setcmdtarg.html