Oracle8i Enterprise JavaBeans and CORBA Developer's Guide Release 8.1.5 A64683-01 |
|
It is possible for a client to access server objects without using the JNDI classes shown in the other sections of this chapter. Such clients can connect to an Oracle server by using straight CosNaming methods. The following example shows how to do this.
import org.omg.CORBA.Object; import org.omg.CosNaming.*; import oracle.aurora.AuroraServices.*; import oracle.aurora.client.Login; public class Client { public static void main(String args[]) throws Exception { // Parse the args if (args.length != 4) { System.out.println("Must supply host/port, username/ password"); System.exit(1); } String host = "sess_iiop://localhost:2481:ORCL"; String port = "2481"; String username = "scott"; String password = "tiger"; // access the Aurora Names Service Bank.Account account = null; Bank.AccountManager manager = null; try { // Get the Name service Object reference (Only ORB specific thing) PublishingContext rootCtx = null; // See the README file with this demo for more about VisiAurora. rootCtx = VisiAurora.getNameService(host, Integer.parseInt(port)); // Get the pre-published login object reference PublishedObject loginObj = null; LoginServer serv = null; NameComponent[] name = new NameComponent[2]; name[0] = new NameComponent("etc", ""); name[1] = new NameComponent("login", ""); // Lookup this object in the name service Object lo = rootCtx.resolve(name); // Make sure it is a published object loginObj = PublishedObjectHelper.narrow(lo); // create and activate this object (non- standard call) lo = loginObj.activate_no_helper(); serv = LoginServerHelper.narrow(lo); // Create a client login proxy object and authenticate to the DB Login login = new Login(serv); login.authenticate(username, password, null); // Now create and get the bank object reference PublishedObject bankObj = null; name[0] = new NameComponent("test", ""); name[1] = new NameComponent("bank", ""); // Lookup this object in the name service Object bo = rootCtx.resolve(name); // Make sure it is a published object bankObj = PublishedObjectHelper.narrow(bo); // create and activate this object (non- standard call) bo = bankObj.activate_no_helper(); manager = Bank.AccountManagerHelper.narrow(bo); account = manager.open("Jack.B.Quick"); float balance = account.balance(); System.out.println ("The balance in Jack.B.Quick's account is $" + balance); } catch (org.omg.CORBA.SystemException ex) { System.out.println("Caught System Ex: " + ex); ex.printStackTrace(); } catch(java.lang.Exception ex) { System.out.println("Caught Unknown Ex: " + ex); ex.printStackTrace(); } } }