]> git.mxchange.org Git - jmailer-ee.git/commitdiff
renamed Mailer to BaseMailer and made it abstract, all methods here should be generic...
authorRoland Haeder <roland@mxchange.org>
Fri, 1 Apr 2016 18:21:15 +0000 (20:21 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 1 Apr 2016 18:21:15 +0000 (20:21 +0200)
nbproject/project.properties
src/org/mxchange/jmailee/model/delivery/BaseMailer.java [new file with mode: 0644]
src/org/mxchange/jmailee/model/delivery/DeliverableEmail.java
src/org/mxchange/jmailee/model/delivery/Mailer.java [deleted file]

index 5e0c317385cdbd956e933dab36c19d1c8daff720..ca819ac8cdcd6bbf05d4a57207fb6e795b5be0bf 100644 (file)
@@ -49,8 +49,8 @@ javac.deprecation=true
 javac.external.vm=true
 javac.processorpath=\
     ${javac.classpath}
-javac.source=1.8
-javac.target=1.8
+javac.source=1.7
+javac.target=1.7
 javac.test.classpath=\
     ${javac.classpath}:\
     ${build.classes.dir}
diff --git a/src/org/mxchange/jmailee/model/delivery/BaseMailer.java b/src/org/mxchange/jmailee/model/delivery/BaseMailer.java
new file mode 100644 (file)
index 0000000..197daa7
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2016 quix0r
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jmailee.model.delivery;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import javax.annotation.Resource;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
+import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
+
+/**
+ * An email class for sending out mails from templates
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public abstract class BaseMailer implements DeliverableEmail {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 14_598_912_753_106L;
+
+       /**
+        * Email session
+        */
+       @Resource (name = "jmail/jjobs")
+       private Session jmailjjobs;
+
+       /**
+        * Logger bean
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
+       /**
+        * Default constructor
+        */
+       protected BaseMailer () {
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Lookup logger
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw
+                       throw new RuntimeException("context.lookup() failed.", ex); //NOI18N
+               }
+       }
+
+       @Override
+       public void sendEmailChangeMail (final MessageProducer messageProducer, final ObjectMessage message, final ChangeableEmailAddress emailChange) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmailChangeMail: messageProducer={0},message={1},emailChange={2} - CALLED", messageProducer, message, emailChange)); //NOI18N
+
+               // All parameters + some sub objects must be set
+               if (null == messageProducer) {
+                       // Throw NPE
+                       throw new NullPointerException("messageProducer is null"); //NOI18N
+               } else if (null == message) {
+                       // Throw NPE again
+                       throw new NullPointerException("message is null"); //NOI18N
+               } else if (null == emailChange) {
+                       // ... and again ...
+                       throw new NullPointerException("emailChange is null"); //NOI18N
+               } else if (emailChange.getEmailChangeUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("emailChange.emailChangeUser is null"); //NOI18N
+               } else if (emailChange.getEmailChangeUser().getUserId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("emailChange.emailChangeUser.userId is null"); //NOI18N
+               } else if (emailChange.getEmailChangeUser().getUserId() < 1) {
+                       // Not valid id
+                       throw new IllegalArgumentException(MessageFormat.format("emailChange.emailChangeUser.userId={0} is invalid.", emailChange.getEmailChangeUser().getUserId())); //NOI18N
+               } else if (emailChange.getEmailChangeUser().getUserContact() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("emailChange.emailChangeUser.userContact is null"); //NOI18N
+               } else if (emailChange.getEmailChangeUser().getUserContact().getContactId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("emailChange.emailChangeUser.userContact.contactId is null"); //NOI18N
+               } else if (emailChange.getEmailChangeUser().getUserContact().getContactId() < 1) {
+                       // Not valid id
+                       throw new IllegalArgumentException(MessageFormat.format("emailChange.emailChangeUser.userContact.contactId={0} is invalid.", emailChange.getEmailChangeUser().getUserContact().getContactId())); //NOI18N
+               } else if (emailChange.getEmailAddress().trim().isEmpty()) {
+                       // Email address is empty
+                       throw new IllegalArgumentException("emailChange.emaiLAddress is empty."); //NOI18N
+               }
+
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       }
+
+       /**
+        * Getter for logger bean
+        * <p>
+        * @return Local logger bean
+        */
+       protected LoggerBeanLocal getLoggerBeanLocal () {
+               return this.loggerBeanLocal;
+       }
+
+       /**
+        * Sends an email to given email address with subject line.
+        * <p>
+        * @param emailAddress Email address for recipient
+        * @param subjectLine  Subject line
+        * @param body         Body part
+        * <p>
+        * @throws NamingException    If the resource cannot be found
+        * @throws MessagingException If something happened on message delivery
+        */
+       protected void sendMail (final String emailAddress, final String subjectLine, final String body) throws NamingException, MessagingException {
+               // Get MIME message instance
+               MimeMessage message = new MimeMessage(this.jmailjjobs);
+
+               // Set subject, recipients and body
+               message.setSubject(subjectLine);
+               message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(emailAddress, true));
+               message.setSentDate(new Date());
+               message.setText(body);
+
+               // Directly send email
+               Transport.send(message);
+       }
+
+}
index 7bd3f1ea452b12e105616f3026661cd6ded8acfc..8d6535b7caa6713a8b08a86ae8ed0c950c72c0c6 100644 (file)
@@ -29,7 +29,7 @@ import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
 public interface DeliverableEmail extends Serializable {
 
        /**
-        * Sends out an email-change mail to the attacher user's email address
+        * Sends out an email-change mail to the attached user's email address
         * <p>
         * @param messageProducer Message product
         * @param message         Message object
diff --git a/src/org/mxchange/jmailee/model/delivery/Mailer.java b/src/org/mxchange/jmailee/model/delivery/Mailer.java
deleted file mode 100644 (file)
index 5af60a2..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (C) 2016 quix0r
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jmailee.model.delivery;
-
-import java.text.MessageFormat;
-import java.util.Date;
-import javax.annotation.Resource;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.Transport;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jcoreeelogger.beans.local.logger.Log;
-import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
-import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
-
-/**
- * An email class for sending out mails from templates
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-public class Mailer implements DeliverableEmail {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 14_598_912_753_106L;
-
-       /**
-        * Email session
-        */
-       @Resource (name = "jmail/jjobs")
-       private Session jmailjjobs;
-
-       /**
-        * Logger bean
-        */
-       @Log
-       private LoggerBeanLocal loggerBeanLocal;
-
-       /**
-        * Default constructor
-        */
-       public Mailer () {
-               try {
-                       // Get initial context
-                       Context context = new InitialContext();
-
-                       // Lookup logger
-                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
-               } catch (final NamingException ex) {
-                       // Continue to throw
-                       throw new RuntimeException("context.lookup() failed.", ex); //NOI18N
-               }
-       }
-
-       @Override
-       public void sendEmailChangeMail (final MessageProducer messageProducer, final ObjectMessage message, final ChangeableEmailAddress emailChange) {
-               // Trace message
-               this.loggerBeanLocal.logTrace(MessageFormat.format("messageProducer={0},message={1},emailChange={2} - CALLED", messageProducer, message, emailChange)); //NOI18N
-
-               // All parameters + some sub objects must be set
-               if (null == messageProducer) {
-                       // Throw NPE
-                       throw new NullPointerException("messageProducer is null"); //NOI18N
-               } else if (null == message) {
-                       // Throw NPE again
-                       throw new NullPointerException("message is null"); //NOI18N
-               } else if (null == emailChange) {
-                       // ... and again ...
-                       throw new NullPointerException("emailChange is null"); //NOI18N
-               } else if (emailChange.getEmailChangeUser() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("emailChange.emailChangeUser is null"); //NOI18N
-               } else if (emailChange.getEmailChangeUser().getUserId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("emailChange.emailChangeUser.userId is null"); //NOI18N
-               } else if (emailChange.getEmailChangeUser().getUserId() < 1) {
-                       // Not valid id
-                       throw new IllegalArgumentException(MessageFormat.format("emailChange.emailChangeUser.userId={0} is invalid.", emailChange.getEmailChangeUser().getUserId())); //NOI18N
-               } else if (emailChange.getEmailChangeUser().getUserContact() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("emailChange.emailChangeUser.userContact is null"); //NOI18N
-               } else if (emailChange.getEmailChangeUser().getUserContact().getContactId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("emailChange.emailChangeUser.userContact.contactId is null"); //NOI18N
-               } else if (emailChange.getEmailChangeUser().getUserContact().getContactId() < 1) {
-                       // Not valid id
-                       throw new IllegalArgumentException(MessageFormat.format("emailChange.emailChangeUser.userContact.contactId={0} is invalid.", emailChange.getEmailChangeUser().getUserContact().getContactId())); //NOI18N
-               } else if (emailChange.getEmailAddress().trim().isEmpty()) {
-                       // Email address is empty
-                       throw new IllegalArgumentException("emailChange.emaiLAddress is empty."); //NOI18N
-               }
-
-               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-       }
-
-       /**
-        * Sends an email to given email address with subject line.
-        * <p>
-        * @param emailAddress Email address for recipient
-        * @param subjectLine  Subject line
-        * @param body         Body part
-        * <p>
-        * @throws NamingException    If the resource cannot be found
-        * @throws MessagingException If something happened on message delivery
-        */
-       private void sendMail (final String emailAddress, final String subjectLine, final String body) throws NamingException, MessagingException {
-               // Get MIME message instance
-               MimeMessage message = new MimeMessage(this.jmailjjobs);
-
-               // Set subject, recipients and body
-               message.setSubject(subjectLine);
-               message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(emailAddress, true));
-               message.setSentDate(new Date());
-               message.setText(body);
-
-               // Directly send email
-               Transport.send(message);
-       }
-
-}