Guest User

Untitled

a guest
Nov 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. public class AccountManagerImpl implements AccountManager {
  2. private MailSender mailSender;
  3. private SimpleMailMessage message;
  4. private AccountDao accountDao;
  5.  
  6. public void setMailSender(MailSender mailSender) {
  7. this.mailSender = mailSender;
  8. }
  9.  
  10. public void setMessage(SimpleMailMessage message) {
  11. this.message = message;
  12. }
  13.  
  14. public void setAccountDao(AccountDao accountDao) {
  15. this.accountDao = accountDao;
  16. }
  17.  
  18. private void sendMail(Exception ex) {
  19. SimpleMailMessage msg = new SimpleMailMessage(this.message);
  20. msg.setText("Encountered exception " + ex.getMessage());
  21. this.mailSender.send(msg);
  22. }
  23.  
  24. public Account getAccount(String accountId) throws AccountNotFoundException, DataAccessException {
  25. try {
  26. return this.accountDao.findAccount(accountId);
  27. } catch (AccountNotFoundException ex) {
  28. sendMail(ex);
  29. throw ex;
  30. } catch (DataAccessException ex) {
  31. sendMail(ex);
  32. throw ex;
  33. }
  34. }
  35.  
  36. public void createAccount(Account account) throws DataAccessException, {
  37. try {
  38. if (isInvalid(account)) {
  39. throw new InvalidAccountException(account);
  40. this.accountDao.saveAccount(account);
  41. }
  42. catch(IOException ex){
  43. sendMail(ex);
  44. throw ex;
  45. }
  46. catch(DataAccessException ex){
  47. sendMail(ex);
  48. throw ex;
  49. }
  50. }
  51. }
  52. }
  53.  
  54. public class AccountManagerImpl implements AccountManager {
  55. private AccountDao accountDao;
  56.  
  57. public void setAccountDao(AccountDao accountDao) {
  58. this.accountDao = accountDao;
  59. }
  60.  
  61. public Account getAccount(String accountId)
  62. throws AccountNotFoundException, DataAccessException {
  63. return this.accountDao.findAccount(accountId);
  64. }
  65.  
  66. public void createAccount(Account account) throws DataAccessException {
  67. this.accountDao.saveAccount(account);
  68. }
  69. }
Add Comment
Please, Sign In to add comment