01: package demo.bank.transaction.implicit;
02:
03: import java.io.*;
04: import org.omg.CosNaming.*;
05: import org.omg.CORBA.ORB;
06: import org.omg.PortableServer.POA;
07:
08: public class Client {
09:
10: public static Account open(String name, float initial_deposit,
11: POA poa, ORB orb, boolean nasty) {
12: try {
13: AccountImpl acc = new AccountImpl(orb, name,
14: initial_deposit, nasty);
15:
16: org.omg.CORBA.Object o = poa.servant_to_reference(acc);
17: return acc._this (orb);
18: } catch (Exception e) {
19: e.printStackTrace();
20: throw new org.omg.CORBA.UNKNOWN();
21: }
22: }
23:
24: public static void main(String[] args) {
25: try {
26: TheBank bank;
27: AccountManager acc_mgr;
28: java.util.Properties props = new java.util.Properties();
29: props
30: .put(
31: "org.omg.PortableInterceptor.ORBInitializerClass.TSServerInit",
32: "org.jacorb.transaction.TransactionInitializer");
33:
34: ORB orb = ORB.init(args, props);
35:
36: NamingContextExt nc = NamingContextExtHelper.narrow(orb
37: .resolve_initial_references("NameService"));
38: NameComponent[] name = new NameComponent[1];
39: name[0] = new NameComponent("DigiBank", "server");
40:
41: acc_mgr = AccountManagerHelper.narrow(nc.resolve(name));
42:
43: POA poa = (POA) orb.resolve_initial_references("RootPOA");
44: poa.the_POAManager().activate();
45:
46: System.out.println("> Opening Accounts Acc1 and Acc 2.");
47:
48: Account a1 = open("Acc1", (float) 199.99, poa, orb, true);
49: Account a2 = open("Acc2", (float) 50.08, poa, orb, false);
50:
51: System.out.println("\n--- Balances ---");
52: System.out.println("Acc1 : " + a1.balance());
53: System.out.println("Acc2 : " + a2.balance());
54:
55: bank = TheBankHelper.narrow(acc_mgr);
56:
57: boolean ok = false;
58: do {
59: System.out
60: .println("> Transfer 100,- from Acc 1 to Acc 2.");
61: try {
62: bank.transfer(a1, a2, 100);
63: ok = true;
64: } catch (Throwable e) {
65: System.out.println("Got: " + e);
66: }
67: } while (!ok);
68:
69: System.out.println("\n--- Balances ---");
70: System.out.println("Acc1 : " + a1.balance());
71: System.out.println("Acc2 : " + a2.balance());
72:
73: do {
74: System.out
75: .println("> Transfer 50,- from Acc 2 to Acc 1.");
76: try {
77: bank.transfer(a2, a1, 50);
78: ok = true;
79: } catch (Throwable e) {
80: System.out.println("Got: " + e);
81: }
82: } while (!ok);
83:
84: System.out.println("\n--- Balances ---");
85: System.out.println("Acc1 : " + a1.balance());
86: System.out.println("Acc2 : " + a2.balance());
87: } catch (Exception e) {
88: e.printStackTrace();
89: }
90: }
91: }
|