import bank.ClientId;
import bank.BankApplicationImpl;
import bank.AccountInfo;
import javax.jdo.JDOHelper;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.IOException;
/**
* @author S.Chassande-Barrioz
*/
public class App {
final static String[] agencyNames = new String[]{"Paris", "London", "New York"};
final static ClientId[] clientsNames = new ClientId[]{
new ClientId("Chassande-Barrioz", "Sebastien", "Gieres"),
new ClientId("Dechamboux", "Pascal", "Saint Ismier"),
new ClientId("Lefebvre", "Alexandre", "Grenoble")
};
public static void main(String[] args) {
System.out.println("Bank created or loaded");
BankApplicationImpl ba = new BankApplicationImpl();
Properties p = new Properties();
try {
p.load(new FileInputStream(args[0]));
} catch (IOException e) {
System.err.println(e.getMessage());
e.printStackTrace(System.err);
System.exit(-1);
}
BankApplicationImpl.pmf = JDOHelper.getPersistenceManagerFactory(p);
String[] accountNumbers = new String[clientsNames.length];
try {
for (int i = 0; i < agencyNames.length; i++) {
ba.createAgency(agencyNames[i]);
System.out.println("Agency '" + agencyNames[i] + "' created");
}
for (int i = 0; i < clientsNames.length; i++) {
ba.createClient(clientsNames[i], agencyNames[0]);
System.out.println("Client '" + clientsNames[i] + "' created");
accountNumbers[i] = ba.createAccount(clientsNames[i], agencyNames[0]);
System.out.println("Account '" + accountNumbers[i] + "' created");
}
printBank(ba);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public static void printBank(BankApplicationImpl ba) throws RemoteException {
List agencies = ba.getAgencies();
for (int i = 0; i < agencies.size(); i++) {
String an = (String) agencies.get(i);
System.out.println("Agency '" + an + "':");
List clients = ba.getClients(an);
for (int j = 0; j < clients.size(); j++) {
ClientId cid = (ClientId) clients.get(j);
System.out.println("\t- Client '" + cid + "':");
List accounts = ba.getAccounts(an, cid);
for (int k = 0; k < accounts.size(); k++) {
AccountInfo ai = (AccountInfo) accounts.get(k);
System.out.println("\t\t- Account " + ai.number + " : " + ai.solde);
}
}
}
}
}