public static Payee findPayee(String name, boolean create) {
if (name == null)
throw new RuntimeException("Payee name is null!");
Payee payee = null;
if (payeeList == null) {
DAOFactory daoFactory = new DAOFactory();
PayeeDAO payeeDao = (PayeeDAO)daoFactory.getDAO("payee");
payeeList = payeeDao.load(null, null, true);
}
boolean found = false;
int count = 0;
Payee currentPayee = null;
while (!found && count<payeeList.size()) {
currentPayee = (Payee)payeeList.get(count);
if (name.equalsIgnoreCase(currentPayee.getName()) ||
(currentPayee.getFilters() != null &&
Pattern.matches(currentPayee.getFilters(), name))) {
found = true;
payee = currentPayee;
}
count++;
}
if (!found) {
payee = new Payee();
payee.setName(name);
DAOFactory daoFactory = new DAOFactory();
PayeeDAO payeeDao = (PayeeDAO)daoFactory.getDAO("payee");
payeeDao.create(payee, false);
}
return payee;
}