BEA Logo BEA Tuxedo Release 8.0

  BEA ホーム  |  イベント  |  ソリューション  |  パートナ  |  製品  |  サービス  |  ダウンロード  |  ディベロッパ・センタ  |  WebSUPPORT

 

   Tuxedo ホーム   |   BEA Jolt   |   先頭へ   |   前へ   |   次へ   |   目次   |   索引

 


オブジェクトを再利用する

次のリストの「Jolt リモート・サービスを拡張する (extendSample. java)」は、JoltRemoteService クラスをサブクラス化する 1 つの方法を示しています。この例では、JoltRemoteService クラスをサブクラス化して TransferService クラスを作成します。TransferService クラスは JoltRemoteService クラスを拡張し、BEA Tuxedo の BANKAPP の TRANSFER サービスを利用する Transfer 機能を追加しています。

次のコード例では、Java 言語の extends キーワードが使用されています。extends キーワードは、Java でベース・クラス (親クラス) をサブクラス化するのに使用されます。次のコードは、JoltRemoteService を拡張する方法のうちの 1 つです。

Jolt リモート・サービスを拡張する (extendSample. java)

/* Copyright 1999 BEA Systems, Inc. All Rights Reserved */
import java.net.*;
import java.io.*;
import bea.jolt.*;
/*
* この Jolt サンプル・コードからの抜粋部分は、JoltRemoteService をカスタマイズ
* する方法を示したものです。Java 言語の "extends" メソッドが使用されています。
*/
class TransferService extends JoltRemoteService
{
public String fromBal;
public String toBal;
    public TransferService( JoltSession session )
{
super("TRANSFER", session);
}
    public String doxfer( int fromAcctNum, int toAcctNum, String amount )
{
/* 以前の入力パラメータすべてを消去する。 */
this.clear();
        /* 入力パラメータを設定する。 */
this.setIntItem("ACCOUNT_ID", 0, fromAcctNum);
this.setIntItem("ACCOUNT_ID", 1, toAcctNum);
this.setString("SAMOUNT", amount );
        try
{
/* 転送サービスを呼び出す。 */
this.call(null);
            /*出力パラメータを取得する。*/
fromBal = this.getStringItemDef("SBALANCE", 0, null);
if (fromBal == null)
return "No balance from Account " +
fromAcctNum;
toBal = this.getStringItemDef("SBALANCE", 1, null);
if (toBal == null)
return "No balance from Account " + toAcctNum;
return null;
}
catch (ApplicationException e)
{
/* トランザクション失敗。理由を返す。 */
return this.getStringDef("STATLIN", "Unknown reason");
}
}
}
class extendSample
{
public static void main( String args[] )
{
JoltSession s_session;
String host;
short port;
TransferService xfer;
String failure;
        if (args.length != 2)
{
System.err.println("Usage:reuseSample host port");
System.exit(1);
/* 初期化用にホスト名とポート番号を取得する。 */
host = args[0];
port = (short)Integer.parseInt(args[1]);
        /* Tuxedo ドメインに接続する準備をする。  */
JoltSessionAttributes attr = new JoltSessionAttributes();
attr.setString(attr.APPADDRESS,"//"+ host+":" + port);
        String username = null;
String userrole = "sw-developer";
String applpasswd = null;
String userpasswd = null;
        /* 設定された認証レベルを調べる。 */
switch (attr.checkAuthenticationLevel())
{
case JoltSessionAttributes.NOAUTH:
break;
case JoltSessionAttributes.APPASSWORD:
applpasswd = "secret8";
break;
case JoltSessionAttributes.USRPASSWORD:
username = "myName";
userpasswd = "BEA#1";
applpasswd = "secret8";
break;
} 
        /* アイドル・タイムアウトなし (0) でログオンする。 */ 
/* ログオフするまでネットワーク接続を維持する。 */ 
attr.setInt(attr.IDLETIMEOUT, 0); 
s_session = new JoltSession(attr, username, userrole, 
userpasswd, applpasswd); 
        /* 
* TransferService は JoltRemoteService を継承し、
* 標準的な BEA Tuxedo の BankApp の TRANSFER サービスを使用します。
このサービス* は異なるパラメータで 2 回呼び出されます。
*"s_session" が初期化済みであると仮定していることに注意してください。
*/ 
        xfer = new TransferService(s_session); 
if ((failure = xfer.doxfer(10000, 10001, "500.00")) != null) 
System.err.println("Tranasaction failed: " + failure); 
else
{
System.out.println("Transaction is done.");
System.out.println("From Acct Balance: "+xfer.fromBal);
System.out.println(" To Acct Balance: "+xfer.toBal); 
} 
        if ((failure = xfer.doxfer(51334, 40343, "$123.25")) != null)
System.err.println("Tranasaction failed: " + failure); 
else 
{
System.out.println("Transaction is done.");
System.out.println("From Acct Balance: "+xfer.fromBal);
System.out.println(" To Acct Balance: "+xfer.toBal); 
}
    } 
}

 

先頭へ戻る 前のトピックへ 次のトピックへ