001: /*
002: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. U.S.
003: * Government Rights - Commercial software. Government users are subject
004: * to the Sun Microsystems, Inc. standard license agreement and
005: * applicable provisions of the FAR and its supplements. Use is subject
006: * to license terms.
007: *
008: * This distribution may include materials developed by third parties.
009: * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
010: * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
011: * other countries.
012: *
013: * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
014: *
015: * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
016: * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
017: * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
018: * en vigueur de la FAR (Federal Acquisition Regulations) et des
019: * supplements a celles-ci. Distribue par des licences qui en
020: * restreignent l'utilisation.
021: *
022: * Cette distribution peut comprendre des composants developpes par des
023: * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
024: * sont des marques de fabrique ou des marques deposees de Sun
025: * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
026: */
027:
028: package savingsaccountclient;
029:
030: import bank.SavingsAccountRemote;
031: import bank.SavingsAccountRemoteHome;
032: import java.math.BigDecimal;
033: import java.util.Collection;
034: import java.util.Iterator;
035: import javax.naming.Context;
036: import javax.naming.InitialContext;
037: import javax.rmi.PortableRemoteObject;
038:
039: /**
040: *
041: * @author blaha
042: */
043: public class Main {
044:
045: /** Creates a new instance of Main */
046: public Main() {
047: }
048:
049: /**
050: * @param args the command line arguments
051: */
052: public static void main(String[] args) {
053: // TODO code application logic here
054: try {
055: Context initial = new InitialContext();
056: Object objref = initial.lookup("ejb/SavingsAccountBean");
057:
058: SavingsAccountRemoteHome home = (SavingsAccountRemoteHome) PortableRemoteObject
059: .narrow(objref, SavingsAccountRemoteHome.class);
060:
061: BigDecimal zeroAmount = new BigDecimal("0.00");
062: SavingsAccountRemote duke = home.create("123", "Duke",
063: "Earl", zeroAmount);
064:
065: duke.credit(new BigDecimal("88.50"));
066: duke.debit(new BigDecimal("20.25"));
067:
068: BigDecimal balance = duke.getBalance();
069: System.out.println("balance = " + balance);
070: duke.remove();
071:
072: SavingsAccountRemote joe = home.create("836", "Joe",
073: "Jones", zeroAmount);
074:
075: joe.credit(new BigDecimal("34.55"));
076:
077: SavingsAccountRemote jones = home.findByPrimaryKey("836");
078:
079: jones.debit(new BigDecimal("2.00"));
080: balance = jones.getBalance();
081: System.out.println("balance = " + balance);
082:
083: SavingsAccountRemote pat = home.create("456", "Pat",
084: "Smith", zeroAmount);
085:
086: pat.credit(new BigDecimal("44.77"));
087:
088: SavingsAccountRemote john = home.create("730", "John",
089: "Smith", zeroAmount);
090:
091: john.credit(new BigDecimal("19.54"));
092:
093: SavingsAccountRemote mary = home.create("268", "Mary",
094: "Smith", zeroAmount);
095:
096: mary.credit(new BigDecimal("100.07"));
097:
098: Collection c = home.findByLastName("Smith");
099: Iterator i = c.iterator();
100:
101: while (i.hasNext()) {
102: SavingsAccountRemote account = (SavingsAccountRemote) i
103: .next();
104: String id = (String) account.getPrimaryKey();
105: BigDecimal amount = account.getBalance();
106:
107: System.out.println(id + ": " + amount);
108: }
109:
110: c = home.findInRange(new BigDecimal("20.00"),
111: new BigDecimal("99.00"));
112: i = c.iterator();
113:
114: while (i.hasNext()) {
115: SavingsAccountRemote account = (SavingsAccountRemote) i
116: .next();
117: String id = (String) account.getPrimaryKey();
118: BigDecimal amount = account.getBalance();
119: System.out.println(id + ": " + amount);
120: }
121:
122: SavingsAccountRemote pete = home.create("904", "Pete",
123: "Carlson", new BigDecimal("5.00"));
124: SavingsAccountRemote sally = home.create("905", "Sally",
125: "Fortney", new BigDecimal("8.00"));
126:
127: home.ChargeForLowBalance(new BigDecimal("10.00"),
128: new BigDecimal("1.00"));
129:
130: BigDecimal reducedAmount = pete.getBalance();
131:
132: System.out.println(reducedAmount);
133: reducedAmount = sally.getBalance();
134: System.out.println(reducedAmount);
135:
136: System.exit(0);
137:
138: } catch (Exception ex) {
139: System.err.println("Exception is caught: "
140: + ex.getMessage());
141: ex.printStackTrace();
142: }
143: }
144:
145: }
|