View Javadoc

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