magoffin.matt.ma2.aop
Class AbstractMailTemplateInterceptor

java.lang.Object
  extended by magoffin.matt.ma2.aop.AbstractMailTemplateInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor
Direct Known Subclasses:
UserEmailInterceptor

public abstract class AbstractMailTemplateInterceptor
extends java.lang.Object
implements org.aopalliance.intercept.MethodInterceptor

Base class for mail merge interceptors.

This interceptor serves as a base for email interceptors using templated email content (mail merge). The invoke(MethodInvocation) method performs the following steps:

  1. Calls getInitialModel(MethodInvocation). This method must return a non-null Map to use for the model data for the mail merge.
  2. Calls Joinpoint.proceed().
  3. Calls postProcessModel(MethodInvocation, Map, Object), passing the model Map previously returned and the result of the method invocation.
  4. Calls getLocale(MethodInvocation, Map, Object).
  5. Calls MailMergeHelper.sendMerge(Locale, ClassLoader, Map, SimpleMailMessage) to perform the mail merge and send the email.

The configurable properties of this class are:

mailMergeSupport
The MailMergeHelper instance to use for sending the mail merge.

Version:
$Revision: 176 $ $Date: 2008-12-28 14:33:18 +1300 (Sun, 28 Dec 2008) $
Author:
Matt Magoffin (spamsqr@msqr.us)

Field Summary
protected  org.apache.commons.logging.Log log
          Class level log.
 
Constructor Summary
AbstractMailTemplateInterceptor()
           
 
Method Summary
protected abstract  java.util.Map<java.lang.String,java.lang.Object> getInitialModel(org.aopalliance.intercept.MethodInvocation invocation)
          Get an initial Map object to use for the model data for the mail merge.
protected  java.util.Locale getLocale(org.aopalliance.intercept.MethodInvocation invocation, java.util.Map<java.lang.String,java.lang.Object> model, java.lang.Object result)
          Get the locale for the email message.
 MailMergeHelper getMailMergeSupport()
           
 java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
           
protected abstract  org.springframework.mail.SimpleMailMessage postProcessModel(org.aopalliance.intercept.MethodInvocation invocation, java.util.Map<java.lang.String,java.lang.Object> model, java.lang.Object result)
          Get a SimpleMailMessage object based on the result of the method invocation.
 void setMailMergeSupport(MailMergeHelper mailMergeSupport)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log
Class level log.

Constructor Detail

AbstractMailTemplateInterceptor

public AbstractMailTemplateInterceptor()
Method Detail

invoke

public final java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
                              throws java.lang.Throwable
Specified by:
invoke in interface org.aopalliance.intercept.MethodInterceptor
Throws:
java.lang.Throwable

getLocale

protected java.util.Locale getLocale(org.aopalliance.intercept.MethodInvocation invocation,
                                     java.util.Map<java.lang.String,java.lang.Object> model,
                                     java.lang.Object result)
Get the locale for the email message.

This implementation simply returns Locale.getDefault(). Extending implementations can use the invocation and invocation result to provide a custom Locale as deisred.

Parameters:
invocation - the current method invocation
model - the model
result - the resut of the current modthod invocation
Returns:
a Locale to use for the mail merge

getInitialModel

protected abstract java.util.Map<java.lang.String,java.lang.Object> getInitialModel(org.aopalliance.intercept.MethodInvocation invocation)
Get an initial Map object to use for the model data for the mail merge.

Parameters:
invocation - the current method invocation
Returns:
Map

postProcessModel

protected abstract org.springframework.mail.SimpleMailMessage postProcessModel(org.aopalliance.intercept.MethodInvocation invocation,
                                                                               java.util.Map<java.lang.String,java.lang.Object> model,
                                                                               java.lang.Object result)
Get a SimpleMailMessage object based on the result of the method invocation.

You can use the MailMergeHelper instance's MailMergeHelper.getMessageTemplate() method to obtain a mail message template, and use the SimpleMailMessage.SimpleMailMessage(org.springframework.mail.SimpleMailMessage) copy constructor to create the SimpleMailMessage to return here. Most likely the only property you'll need to set on the result if the to property.

Parameters:
invocation - the current method invocation
model - the model Map
result - the method invocation result object
Returns:
a SimpleMailMessage object with appropriate information set, i.e. the to property

getMailMergeSupport

public MailMergeHelper getMailMergeSupport()
Returns:
Returns the mailMergeSupport.

setMailMergeSupport

public void setMailMergeSupport(MailMergeHelper mailMergeSupport)
Parameters:
mailMergeSupport - The mailMergeSupport to set.