4.4.2 Client.java

Clientクラスは,bankのアカウントの現在の残高を取得するクライアントアプリケーションをインプリメントします。bankクライアントプログラムは次の手順を実行します。

  1. VisiBroker ORBを初期化します。
  2. AccountManagerオブジェクトにバインドします。
  3. AccountManagerオブジェクトでopenを呼び出して,Accountオブジェクトを取得します。
  4. Accountオブジェクトでbalanceを呼び出して,残高を取得します。
コードサンプル4-2 クライアント側のプログラム(Java)

public class Client {
  public static void main(String[ ] args){
     // Initialize the ORB.
     org.omg.CORBA.ORB orb =
                        org.omg.CORBA.ORB.init(args, null);
     // Get the manager Id
     byte[ ] managerId = "BankManager".getBytes();
     // Locate an account manager.
     // Give the full POA name and the servant ID.
     Bank.AccountManager manager =
           Bank.AccountManagerHelper.bind(orb,
                                          "/bank_agent_poa",
                                           managerId);
     // use args[0] as the account name, or a default.
     String name = args.length > 0 ? args[0] : "Jack B. Quick";
     // Request the account manager to open a named account.
     Bank.Account account = manager.open(name);
     // Get the balance of the account.
     float balance = account.balance();
     // Print out the balance.
     System.out.println("The balance in " + name +
                        "'s account is $" + balance);
  }
}