View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.xmpp.filters;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.routing.filter.Filter;
11  
12  import org.jivesoftware.smack.filter.PacketFilter;
13  import org.jivesoftware.smack.packet.Packet;
14  
15  /**
16   * <code>AbstractXmppFilter</code> is a filter adapter so that Smack Filters can be
17   * configured as Mule filters.
18   */
19  public abstract class AbstractXmppFilter implements Filter, PacketFilter
20  {
21      protected volatile PacketFilter delegate;
22  
23      public boolean accept(Packet packet)
24      {
25          if (delegate == null)
26          {
27              delegate = createFilter();
28          }
29  
30          return delegate.accept(packet);
31      }
32  
33      public boolean accept(MuleMessage message)
34      {
35          // If we have received a MuleMessage the filter has already been applied
36          return true;
37      }
38  
39      protected abstract PacketFilter createFilter();
40  }