Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AccountManagerImpl implements AccountManager {
- private MailSender mailSender;
- private SimpleMailMessage message;
- private AccountDao accountDao;
- public void setMailSender(MailSender mailSender) {
- this.mailSender = mailSender;
- }
- public void setMessage(SimpleMailMessage message) {
- this.message = message;
- }
- public void setAccountDao(AccountDao accountDao) {
- this.accountDao = accountDao;
- }
- private void sendMail(Exception ex) {
- SimpleMailMessage msg = new SimpleMailMessage(this.message);
- msg.setText("Encountered exception " + ex.getMessage());
- this.mailSender.send(msg);
- }
- public Account getAccount(String accountId) throws AccountNotFoundException, DataAccessException {
- try {
- return this.accountDao.findAccount(accountId);
- } catch (AccountNotFoundException ex) {
- sendMail(ex);
- throw ex;
- } catch (DataAccessException ex) {
- sendMail(ex);
- throw ex;
- }
- }
- public void createAccount(Account account) throws DataAccessException, {
- try {
- if (isInvalid(account)) {
- throw new InvalidAccountException(account);
- this.accountDao.saveAccount(account);
- }
- catch(IOException ex){
- sendMail(ex);
- throw ex;
- }
- catch(DataAccessException ex){
- sendMail(ex);
- throw ex;
- }
- }
- }
- }
- public class AccountManagerImpl implements AccountManager {
- private AccountDao accountDao;
- public void setAccountDao(AccountDao accountDao) {
- this.accountDao = accountDao;
- }
- public Account getAccount(String accountId)
- throws AccountNotFoundException, DataAccessException {
- return this.accountDao.findAccount(accountId);
- }
- public void createAccount(Account account) throws DataAccessException {
- this.accountDao.saveAccount(account);
- }
- }
Add Comment
Please, Sign In to add comment