KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > savingsaccountclient > Main


1 /*
2  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. U.S.
3  * Government Rights - Commercial software. Government users are subject
4  * to the Sun Microsystems, Inc. standard license agreement and
5  * applicable provisions of the FAR and its supplements. Use is subject
6  * to license terms.
7  *
8  * This distribution may include materials developed by third parties.
9  * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
10  * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
11  * other countries.
12  *
13  * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
14  *
15  * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
16  * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
17  * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
18  * en vigueur de la FAR (Federal Acquisition Regulations) et des
19  * supplements a celles-ci. Distribue par des licences qui en
20  * restreignent l'utilisation.
21  *
22  * Cette distribution peut comprendre des composants developpes par des
23  * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
24  * sont des marques de fabrique ou des marques deposees de Sun
25  * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
26  */

27
28 package savingsaccountclient;
29
30 import bank.SavingsAccountRemote;
31 import bank.SavingsAccountRemoteHome;
32 import java.math.BigDecimal JavaDoc;
33 import java.util.Collection JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import javax.naming.Context JavaDoc;
36 import javax.naming.InitialContext JavaDoc;
37 import javax.rmi.PortableRemoteObject JavaDoc;
38
39 /**
40  *
41  * @author blaha
42  */

43 public class Main {
44     
45     /** Creates a new instance of Main */
46     public Main() {
47     }
48     
49     /**
50      * @param args the command line arguments
51      */

52     public static void main(String JavaDoc[] args) {
53         // TODO code application logic here
54
try{
55         Context JavaDoc initial = new InitialContext JavaDoc();
56             Object JavaDoc objref =
57                 initial.lookup("ejb/SavingsAccountBean");
58                                                                                             
59             SavingsAccountRemoteHome home =
60                 (SavingsAccountRemoteHome) PortableRemoteObject.narrow(objref,
61                     SavingsAccountRemoteHome.class);
62                                                                                             
63             BigDecimal JavaDoc zeroAmount = new BigDecimal JavaDoc("0.00");
64             SavingsAccountRemote duke =
65                 home.create("123", "Duke", "Earl", zeroAmount);
66                                                                                             
67             duke.credit(new BigDecimal JavaDoc("88.50"));
68             duke.debit(new BigDecimal JavaDoc("20.25"));
69                                                                                             
70             BigDecimal JavaDoc balance = duke.getBalance();
71             System.out.println("balance = " + balance);
72             duke.remove();
73             
74             SavingsAccountRemote joe = home.create("836", "Joe", "Jones", zeroAmount);
75                                                                                             
76             joe.credit(new BigDecimal JavaDoc("34.55"));
77                                                                                             
78             SavingsAccountRemote jones = home.findByPrimaryKey("836");
79                                                                                             
80             jones.debit(new BigDecimal JavaDoc("2.00"));
81             balance = jones.getBalance();
82             System.out.println("balance = " + balance);
83                                                                                             
84             SavingsAccountRemote pat = home.create("456", "Pat", "Smith", zeroAmount);
85                                                                                             
86             pat.credit(new BigDecimal JavaDoc("44.77"));
87                                                                                             
88             SavingsAccountRemote john =
89                 home.create("730", "John", "Smith", zeroAmount);
90                                                                                             
91             john.credit(new BigDecimal JavaDoc("19.54"));
92                                                                                             
93             SavingsAccountRemote mary =
94                 home.create("268", "Mary", "Smith", zeroAmount);
95                                                                                             
96             mary.credit(new BigDecimal JavaDoc("100.07"));
97                                                                                             
98             Collection JavaDoc c = home.findByLastName("Smith");
99             Iterator JavaDoc i = c.iterator();
100                                                                                             
101             while (i.hasNext()) {
102                 SavingsAccountRemote account = (SavingsAccountRemote) i.next();
103                 String JavaDoc id = (String JavaDoc) account.getPrimaryKey();
104                 BigDecimal JavaDoc amount = account.getBalance();
105                                                                                             
106                 System.out.println(id + ": " + amount);
107             }
108                                                                                             
109             c = home.findInRange(new BigDecimal JavaDoc("20.00"),
110                     new BigDecimal JavaDoc("99.00"));
111             i = c.iterator();
112                                                                                             
113             while (i.hasNext()) {
114                 SavingsAccountRemote account = (SavingsAccountRemote) i.next();
115                 String JavaDoc id = (String JavaDoc) account.getPrimaryKey();
116                 BigDecimal JavaDoc amount = account.getBalance();
117                             System.out.println(id + ": " + amount);
118             }
119                                                                                             
120             SavingsAccountRemote pete =
121                 home.create("904", "Pete", "Carlson", new BigDecimal JavaDoc("5.00"));
122             SavingsAccountRemote sally =
123                 home.create("905", "Sally", "Fortney", new BigDecimal JavaDoc("8.00"));
124                                                                                             
125             home.ChargeForLowBalance(new BigDecimal JavaDoc("10.00"),
126                 new BigDecimal JavaDoc("1.00"));
127                                                                                             
128             BigDecimal JavaDoc reducedAmount = pete.getBalance();
129                                                                                             
130             System.out.println(reducedAmount);
131             reducedAmount = sally.getBalance();
132             System.out.println(reducedAmount);
133                                                                                             
134             System.exit(0);
135             
136         }catch(Exception JavaDoc ex){
137             System.err.println("Exception is caught: " + ex.getMessage());
138             ex.printStackTrace();
139         }
140     }
141     
142 }
143
Popular Tags