1 2 import bank.ClientId; 3 import bank.BankApplicationImpl; 4 import bank.AccountInfo; 5 6 import javax.jdo.JDOHelper; 7 import java.rmi.RemoteException ; 8 import java.util.List ; 9 import java.util.Properties ; 10 import java.io.FileInputStream ; 11 import java.io.IOException ; 12 13 16 public class App { 17 final static String [] agencyNames = new String []{"Paris", "London", "New York"}; 18 final static ClientId[] clientsNames = new ClientId[]{ 19 new ClientId("Chassande-Barrioz", "Sebastien", "Gieres"), 20 new ClientId("Dechamboux", "Pascal", "Saint Ismier"), 21 new ClientId("Lefebvre", "Alexandre", "Grenoble") 22 }; 23 24 public static void main(String [] args) { 25 System.out.println("Bank created or loaded"); 26 BankApplicationImpl ba = new BankApplicationImpl(); 27 28 Properties p = new Properties (); 29 try { 30 p.load(new FileInputStream (args[0])); 31 } catch (IOException e) { 32 System.err.println(e.getMessage()); 33 e.printStackTrace(System.err); 34 System.exit(-1); 35 } 36 BankApplicationImpl.pmf = JDOHelper.getPersistenceManagerFactory(p); 37 38 String [] accountNumbers = new String [clientsNames.length]; 39 try { 40 for (int i = 0; i < agencyNames.length; i++) { 41 ba.createAgency(agencyNames[i]); 42 System.out.println("Agency '" + agencyNames[i] + "' created"); 43 } 44 45 for (int i = 0; i < clientsNames.length; i++) { 46 ba.createClient(clientsNames[i], agencyNames[0]); 47 System.out.println("Client '" + clientsNames[i] + "' created"); 48 accountNumbers[i] = ba.createAccount(clientsNames[i], agencyNames[0]); 49 System.out.println("Account '" + accountNumbers[i] + "' created"); 50 } 51 52 printBank(ba); 53 } catch (RemoteException e) { 54 e.printStackTrace(); 55 } 56 57 } 58 59 public static void printBank(BankApplicationImpl ba) throws RemoteException { 60 List agencies = ba.getAgencies(); 61 for (int i = 0; i < agencies.size(); i++) { 62 String an = (String ) agencies.get(i); 63 System.out.println("Agency '" + an + "':"); 64 List clients = ba.getClients(an); 65 for (int j = 0; j < clients.size(); j++) { 66 ClientId cid = (ClientId) clients.get(j); 67 System.out.println("\t- Client '" + cid + "':"); 68 List accounts = ba.getAccounts(an, cid); 69 for (int k = 0; k < accounts.size(); k++) { 70 AccountInfo ai = (AccountInfo) accounts.get(k); 71 System.out.println("\t\t- Account " + ai.number + " : " + ai.solde); 72 } 73 } 74 } 75 } 76 77 } 78
| Popular Tags
|