View Javadoc

1   /*
2    * $Id: EqualsFilter.java 10489 2008-01-23 17:53:38Z dfeist $
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.api.routing.filter.ObjectFilter;
16  
17  /**
18   * <code>EqualsFilter</code> is a filter for comparing two objects using the
19   * equals() method.
20   */
21  public class EqualsFilter implements Filter, ObjectFilter
22  {
23      private Object pattern;
24  
25      public EqualsFilter()
26      {
27          super();
28      }
29  
30      public EqualsFilter(Object compareTo)
31      {
32          this.pattern = compareTo;
33      }
34  
35      public boolean accept(MuleMessage message)
36      {
37          return accept(message.getPayload());
38      }
39  
40      public boolean accept(Object object)
41      {
42          if (object == null && pattern == null)
43          {
44              return true;
45          }
46  
47          if (object == null || pattern == null)
48          {
49              return false;
50          }
51  
52          return pattern.equals(object);
53      }
54  
55      public Object getPattern()
56      {
57          return pattern;
58      }
59  
60      public void setPattern(Object pattern)
61      {
62          this.pattern = pattern;
63      }
64  
65  }