View Javadoc

1   /*
2    * $Id: XmppPacketTypeFilter.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.xmpp.filters;
12  
13  import org.mule.util.ClassUtils;
14  
15  import org.jivesoftware.smack.filter.PacketFilter;
16  
17  /**
18   * <code>XmppPacketTypeFilter</code> is an Xmpp PacketTypeFilter adapter.
19   */
20  public class XmppPacketTypeFilter extends AbstractXmppFilter
21  {
22      private volatile Class<?> expectedType;
23  
24      public XmppPacketTypeFilter()
25      {
26          super();
27      }
28  
29      public XmppPacketTypeFilter(Class<?> expectedType)
30      {
31          setExpectedType(expectedType);
32      }
33  
34      public Class<?> getExpectedType()
35      {
36          return expectedType;
37      }
38  
39      public void setExpectedType(Class<?> expectedType)
40      {
41          this.expectedType = expectedType;
42      }
43  
44      @Override
45      protected PacketFilter createFilter()
46      {
47          return new org.jivesoftware.smack.filter.PacketTypeFilter(expectedType);
48      }
49      
50      @Override
51      public boolean equals(Object obj)
52      {
53          if (this == obj) return true;
54          if (obj == null || getClass() != obj.getClass()) return false;
55  
56          XmppPacketTypeFilter other = (XmppPacketTypeFilter) obj;
57          return ClassUtils.equal(expectedType, other.expectedType);
58      }
59  
60      @Override
61      public int hashCode()
62      {
63          return ClassUtils.hash(new Object[]{this.getClass(), expectedType});
64      }
65  }