KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistentaccount > Client


1 /*
2  * Copyright (c) 2003 by The Jackass Team
3  * Licensed under the Open Software License version 2.0
4  */

5 package persistentaccount;
6
7 import org.omg.CORBA.ORB JavaDoc;
8 import org.omg.CosNaming.NamingContextExt JavaDoc;
9 import org.omg.CosNaming.NamingContextExtHelper JavaDoc;
10
11 import account.AccountData;
12 import account.AccountManager;
13 import account.AccountManagerHelper;
14 import account.OperationFailed;
15
16 /**
17  *
18  * @author Carlos Arévalo
19  */

20 public class Client
21 {
22     public static void main(String JavaDoc[] args)
23     {
24         try
25         {
26             ORB JavaDoc orb = org.omg.CORBA.ORB.init(args, null);
27
28             org.omg.CORBA.Object JavaDoc obj = null;
29             obj = orb.resolve_initial_references("NameService");
30             NamingContextExt JavaDoc rootContext = NamingContextExtHelper.narrow(obj);
31
32             obj = rootContext.resolve_str("persistent_account");
33             AccountManager accManager = AccountManagerHelper.narrow(obj);
34
35             //accManager.createAccount(1, "John Smith", 9000.0);
36
accManager.deposit(1, 1000.0);
37             double balance = accManager.getBalance(1);
38             System.out.println("Balance = " + balance);
39             AccountData account = accManager.getAccountData(1);
40             System.out.println("Account ID = " + account.id);
41             System.out.println("Name = " + account.name);
42             System.out.println("Balance = " + account.balance);
43         }
44         catch (OperationFailed e)
45         {
46             System.out.println("Operation failed " + e.reason);
47         }
48         catch (Exception JavaDoc e)
49         {
50             System.out.println("Error: " + e.getMessage());
51         }
52     }
53 }
54
Popular Tags