View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.email.filters;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.routing.filter.Filter;
11  import org.mule.util.ClassUtils;
12  
13  import javax.mail.Message;
14  
15  import org.apache.commons.logging.Log;
16  import org.apache.commons.logging.LogFactory;
17  
18  /**
19   * <code>AbstractMailFilter</code> is a base class for all javax.mail.Message
20   * filters.
21   */
22  public abstract class AbstractMailFilter implements Filter
23  {
24      /**
25       * logger used by this class
26       */
27      protected transient Log logger = LogFactory.getLog(getClass());
28  
29      public final boolean accept(MuleMessage message)
30      {
31          if (message == null)
32          {
33              return false;
34          }
35  
36          Object object = message.getPayload();
37          if (object instanceof Message)
38          {
39              return accept((Message)object);
40          }
41          else
42          {
43              throw new IllegalArgumentException("The Mail filter does not understand: "
44                                                 + ClassUtils.getSimpleName(object.getClass()));
45          }
46      }
47  
48      public abstract boolean accept(Message message);
49  }