WebSphere Application Server Network Deployment for i5/OS, Version 6.1   
             オペレーティング・システム: i5/OS

             目次と検索結果のパーソナライズ化

例: TargetableCommand インターフェースからのメソッドの実装

TargetableCommand インターフェースは、アプリケーション・プログラマーが実装する 必要がある 1 つのメソッド performExecute を宣言します。

ModifyCheckingAccountCmdImpl クラス内の TargetableCommand インターフェースからのメソッド

以下のコード例に、ModifyCheckingAccountCmd コマンドの実装を示します。 performExecute メソッドの実装は、以下のとおりです。
  • 現在の残高を保管します (コマンドは、補正器コマンドによって元に戻すことが 可能になります)。
  • 新規残高を計算します。
  • 現在の残高を新規残高に設定します。
  • 値がクライアントに戻されるように、hasOutputProperties メソッドが true を戻すことを 確認します。
さらに、ModifyCheckingAccountCmdImpl クラスは setOutputProperties メソッドのデフォルト実装をオーバーライドします。
...
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.");
}
}
...
}



関連タスク
コマンド・インターフェースの実装
参照トピック    

ご利用条件 | フィードバック

最終更新: Jan 21, 2008 8:28:52 PM EST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.nd.iseries.doc/info/iseriesnd/ae/rcmd_implmethtcint.html