1 5 package account; 6 7 import java.util.Hashtable ; 8 9 import ve.luz.ica.jackass.component.ApplicationContext; 10 import ve.luz.ica.jackass.component.StatelessContext; 11 import ve.luz.ica.jackass.component.StatelessHook; 12 13 17 public class AccountManagerImpl extends AccountManagerPOA implements StatelessHook 18 { 19 private StatelessContext compContext = null; 20 private ApplicationContext appContext = null; 21 private static final String ACCOUNT_NOT_FOUND = "Account not found"; 22 23 private static Hashtable accounts = new Hashtable (); 24 25 private AccountData getAccount(int id) throws Exception 26 { 27 AccountData account = (AccountData) accounts.get(new Integer (id)); 28 if (account == null) 29 { 30 throw new Exception (ACCOUNT_NOT_FOUND); 31 } 32 return account; 33 } 34 35 38 public void createAccount(int id, String name, double initialBalance) throws OperationFailed 39 { 40 AccountData account = new AccountData(id, name, initialBalance); 41 accounts.put(new Integer (id), account); 42 } 43 44 47 public void deleteAccount(int id) throws OperationFailed 48 { 49 accounts.remove(new Integer (id)); 50 } 51 52 55 public void deposit(int id, double amount) throws OperationFailed 56 { 57 try 58 { 59 AccountData account = this.getAccount(id); 60 account.balance += amount; 61 } 62 catch (Exception e) 63 { 64 throw new OperationFailed(e.getMessage()); 65 } 66 } 67 68 71 public void withdraw(int id, double amount) throws OperationFailed 72 { 73 try 74 { 75 AccountData account = this.getAccount(id); 76 account.balance -= amount; 77 } 78 catch (Exception e) 79 { 80 throw new OperationFailed(e.getMessage()); 81 } 82 } 83 84 87 public double getBalance(int id) throws OperationFailed 88 { 89 try 90 { 91 AccountData account = this.getAccount(id); 92 return account.balance; 93 } 94 catch (Exception e) 95 { 96 throw new OperationFailed(e.getMessage()); 97 } 98 } 99 100 103 public AccountData getAccountData(int id) throws OperationFailed 104 { 105 try 106 { 107 AccountData account = this.getAccount(id); 108 return account; 109 } 110 catch (Exception e) 111 { 112 throw new OperationFailed(e.getMessage()); 113 } 114 } 115 116 119 public void jackassSetContexts(ApplicationContext appCtx, StatelessContext compCtx) 120 { 121 this.appContext = appCtx; 122 this.compContext = compCtx; 123 } 124 125 128 public void jackassCreate() 129 { 130 } 132 133 136 public void jackassRemove() 137 { 138 } 140 } 141 | Popular Tags |