package bank; import org.omg.CORBA.*; import org.omg.PortableServer.*; import java.util.List; import java.util.Iterator; public class BankImpl extends bank.BankPOA { public bank.Account openAccount (bank.AccountInformation accInfo) throws bank.UnknownException { try { DBUtils.createAccount(accInfo); POA accountPOA = this._poa().the_parent().find_POA("AccountPOA",true); String accNum = accInfo.accNum; Account theAccount = AccountHelper.narrow( accountPOA.create_reference_with_id(accNum.getBytes(),"IDL:bank/Account:1.0")); return theAccount; } catch(Exception e) { throw new UnknownException(e.getMessage()); } } public void closeAccount (String accNum) throws bank.UnknownException { try { DBUtils.removeAccount(accNum); POA accountPOA = this._poa().the_parent().find_POA("AccountPOA",true); accountPOA.deactivate_object(accNum.getBytes()); } catch(org.omg.PortableServer.POAPackage.ObjectNotActive e) { } catch(Exception e) { throw new UnknownException(e.getMessage()); } } public bank.Account[] findAccounts (bank.AccountInformation accInfo) throws bank.UnknownException { try { // find the Accounts and return references.. List accountNumbers = DBUtils.findAccounts(accInfo); POA accountPOA = this._poa().the_parent().find_POA("AccountPOA",true); Account[] accounts = new Account[accountNumbers.size()]; Iterator it = accountNumbers.iterator(); int i=0; while(it.hasNext()) { accounts[i] = AccountHelper.narrow( accountPOA.create_reference_with_id(((String)it.next()).getBytes(),"IDL:bank/Account:1.0")); i++; } return accounts; } catch(Exception e) { throw new UnknownException(e.getMessage()); } } }