View Javadoc

1   /*
2    * $Id: PayloadTypeFilter.java 11477 2008-03-22 00:18:50Z rossmason $
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.routing.filters;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.routing.filter.Filter;
15  import org.mule.util.ClassUtils;
16  
17  /**
18   * <code>PayloadTypeFilter</code> filters based on the type of the object received.
19   */
20  
21  public class PayloadTypeFilter implements Filter
22  {
23      private Class expectedType;
24  
25      public PayloadTypeFilter()
26      {
27          super();
28      }
29  
30      public PayloadTypeFilter(String expectedType) throws ClassNotFoundException
31      {
32          this(ClassUtils.loadClass(expectedType, PayloadTypeFilter.class));
33      }
34  
35      public PayloadTypeFilter(Class expectedType)
36      {
37          this.expectedType = expectedType;
38      }
39  
40      public boolean accept(MuleMessage message)
41      {
42          return (expectedType != null ? expectedType.isAssignableFrom(message.getPayload().getClass()) : false);
43      }
44  
45      public Class getExpectedType()
46      {
47          return expectedType;
48      }
49  
50      public void setExpectedType(Class expectedType)
51      {
52          this.expectedType = expectedType;
53      }
54  
55  }