+ @Override
+ public void sendDeliverableMail (final WrapableEmailDelivery emailWrapper) throws MessagingException {
+ // Log trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendDeliverableMail: emailWrapper={0} - CALLED!", emailWrapper)); //NOI18N
+
+ // The parameter must be valid
+ if (null == emailWrapper) {
+ // Throw NPE
+ throw new NullPointerException("emailWrapper is null"); //NOI18N
+ } else if (emailWrapper.getRecipient() == null) {
+ // Throw NPE again
+ throw new NullPointerException("emailWrapper.recipient is null"); //NOI18N
+ } else if (emailWrapper.getSubjectLine() == null) {
+ // ... and again
+ throw new NullPointerException("emailWrapper.subjectLine is null"); //NOI18N
+ } else if (emailWrapper.getSubjectLine().isEmpty()) {
+ // Is empty
+ throw new IllegalArgumentException("emailWrapper.subjectLine is empty"); //NOI18N
+ } else if (emailWrapper.getTemplateName() == null) {
+ // ... and again
+ throw new NullPointerException("emailWrapper.templateName is null"); //NOI18N
+ } else if (emailWrapper.getTemplateName().isEmpty()) {
+ // Is empty
+ throw new IllegalArgumentException("emailWrapper.templateName is empty"); //NOI18N
+ } else if (emailWrapper.getLocale() == null) {
+ // Throw NPE again
+ throw new NullPointerException("emailWrapper.locale is null"); //NOI18N
+ }
+
+ // All required data is set, load template
+ Template template = this.getTemplateEngine().getTemplate(String.format("./templates/%s/%s.vm", emailWrapper.getLocale().getLanguage().toLowerCase(), emailWrapper.getTemplateName())); //NOI18N
+
+ // Init context
+ VelocityContext context = new VelocityContext();
+
+ // Are some variables set?
+ if ((emailWrapper.getTemplateVariables() != null) && (!emailWrapper.getTemplateVariables().isEmpty())) {
+ // Add all variables
+ for (Map.Entry<Object, Object> entry : emailWrapper.getTemplateVariables().entrySet()) {
+ // Get key/value
+ String key = (String) entry.getKey();
+ String value = (String) entry.getValue();
+
+ // Both should not be empty
+ if (null == key) {
+ // Throw NPE
+ throw new NullPointerException("key is null"); //NOI18N
+ } else if (null == value) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("value for key={0} is null", key)); //NOI18N
+ }
+
+ // Set it
+ context.put(key, value);
+ }
+ }
+
+ // Send the email
+ this.sendMailTemplate(template, context, emailWrapper, this.mailSession);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("sendDeliverableMail: EXIT!"); //NOI18N
+ }
+