Borland(R) Enterprise Server VisiBroker(R) デベロッパーズガイド
クライアントアプリケーションはResolverにバインドする必要はなく,コードサンプル26-2に示すようにbind()メソッドの呼び出し時にURLを指定するだけです。バインドはURLをオブジェクト名として受け取ります。URLが無効な場合はInvalidURL例外が発生します。bind()メソッドは透過的にlocate()メソッドを呼び出します。locate()メソッドの使用例については,コードサンプル26-3を参照してください。
// ResolverClient.java import com.inprise.vbroker.URLNaming.*; public class ResolverClient { public static void main(String[ ] args) { if (args.length == 0) { System.out.println( "Usage: vbj Client <URL string> [Account name]"); return; } String url = args[0]; try { // Initialize the ORB. org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null); // Obtain the URLNaming Resolver Resolver resolver = ResolverHelper.narrow( orb.resolve_initial_references( "URLNamingResolver")); // Locate the object Bank.AccountManager manager = Bank.AccountManagerHelper. narrow(resolver.locate(url)); // use args[0] as the account name, or a default. String name = args.length > 1 ? args[1] : "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); } catch(Exception e) { e.printStackTrace(); } } }
// Client.java public class Client { public static void main(String[ ] args) { if (args.length == 0) { System.out.println( "Usage: vbj Client <URL string> [Account name ]"); return; } String url = args[0]; // Initialize the ORB. org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null); // Locate the object Bank.AccountManager manager = Bank.AccountManagerHelper.bind(orb, url); // use args[0] as the account name, or a default. String name = args.length > 1 ? args[1] : "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); } }
All Rights Reserved. Copyright (C) 2008, Hitachi, Ltd.
COPYRIGHT (C) 1992-2004 Borland Software Corporation. All rights reserved.