View Javadoc

1   /*
2    * $Id: AbstractMailFilter.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.providers.email.filters;
12  
13  import org.mule.umo.UMOFilter;
14  import org.mule.umo.UMOMessage;
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 UMOFilter
27  {
28      /**
29       * logger used by this class
30       */
31      protected transient Log logger = LogFactory.getLog(getClass());
32  
33      public final boolean accept(UMOMessage 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  }