]> git.mxchange.org Git - jmailer-ee.git/blob - src/org/mxchange/jmailee/model/delivery/wrapper/EmailDeliveryWrapper.java
Continued:
[jmailer-ee.git] / src / org / mxchange / jmailee / model / delivery / wrapper / EmailDeliveryWrapper.java
1 /*
2  * Copyright (C) 2016 - 2022 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jmailee.model.delivery.wrapper;
18
19 import java.util.Locale;
20 import java.util.Properties;
21 import javax.mail.Address;
22
23 /**
24  * A wrapper class for email delivery.
25  * <p>
26  * @author Roland Häder<roland@mxchange.org>
27  */
28 public class EmailDeliveryWrapper implements WrapableEmailDelivery {
29
30         /**
31          * Serial number
32          */
33         private static final long serialVersionUID = 518_209_689_877_185_914L;
34
35         /**
36          * Locale instance for language
37          */
38         private Locale locale;
39
40         /**
41          * Recipient email address
42          */
43         private Address recipientAddress;
44
45         /**
46          * Subject line
47          */
48         private String subjectLine;
49
50         /**
51          * Template name
52          */
53         private String templateName;
54
55         /**
56          * Template variables
57          */
58         private Properties templateVariables;
59
60         /**
61          * Constructor with all required fields
62          * <p>
63          * @param recipientAddress  Recipient's email address
64          * @param subjectLine       Subject line (internationalized)
65          * @param templateName      Template name
66          * @param templateVariables Any template variables, at least one
67          * @param locale            Recipient's locale
68          */
69         public EmailDeliveryWrapper (final Address recipientAddress, final String subjectLine, final String templateName, final Properties templateVariables, final Locale locale) {
70                 // Are all parameter set?
71                 if (null == recipientAddress) {
72                         // Throw NPE
73                         throw new NullPointerException("recipientAddress is null"); //NOI18N
74                 } else if (null == subjectLine) {
75                         // Throw it again
76                         throw new NullPointerException("subjectLine is null"); //NOI18N
77                 } else if (subjectLine.isEmpty()) {
78                         // Throw IAE
79                         throw new IllegalArgumentException("subjectLine is empty"); //NOI18N
80                 } else if (null == templateName) {
81                         // Throw NPE
82                         throw new NullPointerException("templateName is null"); //NOI18N
83                 } else if (templateName.isEmpty()) {
84                         // Throw IAE
85                         throw new IllegalArgumentException("templateName is empty"); //NOI18N
86                 } else if (null == templateVariables) {
87                         // Throw NPE
88                         throw new NullPointerException("templateVariables is null"); //NOI18N
89                 } else if (templateVariables.isEmpty()) {
90                         // At least one parameter should be there
91                         throw new IllegalArgumentException("templatesVariables should have at least one parameter set."); //NOI18N
92                 } else if (null == locale) {
93                         // Throw NPE
94                         throw new NullPointerException("locale is null"); //NOI18N
95                 }
96
97                 // Set all fields
98                 this.recipientAddress = recipientAddress;
99                 this.subjectLine = subjectLine;
100                 this.templateName = templateName;
101                 this.templateVariables = templateVariables;
102                 this.locale = locale;
103         }
104
105         @Override
106         public Locale getLocale () {
107                 return this.locale;
108         }
109
110         @Override
111         public void setLocale (final Locale locale) {
112                 this.locale = locale;
113         }
114
115         @Override
116         public Address getRecipientAddress () {
117                 return this.recipientAddress;
118         }
119
120         @Override
121         public void setRecipientAddress (final Address recipientAddress) {
122                 this.recipientAddress = recipientAddress;
123         }
124
125         @Override
126         public String getSubjectLine () {
127                 return this.subjectLine;
128         }
129
130         @Override
131         public void setSubjectLine (final String subjectLine) {
132                 this.subjectLine = subjectLine;
133         }
134
135         @Override
136         public String getTemplateName () {
137                 return this.templateName;
138         }
139
140         @Override
141         public void setTemplateName (final String templateName) {
142                 this.templateName = templateName;
143         }
144
145         @Override
146         @SuppressWarnings ("ReturnOfCollectionOrArrayField")
147         public Properties getTemplateVariables () {
148                 return this.templateVariables;
149         }
150
151         @Override
152         @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
153         public void setTemplateVariables (final Properties templateVariables) {
154                 this.templateVariables = templateVariables;
155         }
156
157 }