View Javadoc

1   /*
2    * $Id: AbstractXmppFilter.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.xmpp.filters;
12  
13  import org.mule.umo.UMOFilter;
14  import org.mule.umo.UMOMessage;
15  
16  import org.jivesoftware.smack.filter.PacketFilter;
17  import org.jivesoftware.smack.packet.Packet;
18  
19  /**
20   * <code>AbstractXmppFilter</code> is a filter adapter so that Smack Filters can be
21   * configured as Mule filters.
22   */
23  public abstract class AbstractXmppFilter implements UMOFilter, PacketFilter
24  {
25      protected volatile PacketFilter delegate;
26  
27      public boolean accept(Packet packet)
28      {
29          if (delegate == null)
30          {
31              delegate = createFilter();
32          }
33  
34          return delegate.accept(packet);
35      }
36  
37      public boolean accept(UMOMessage message)
38      {
39          // If we have received a UMOMessage the filter has already been applied
40          return true;
41      }
42  
43      protected abstract PacketFilter createFilter();
44  
45  }