View Javadoc

1   /*
2    * $Id: XmppMessageConversation.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;
12  
13  import org.mule.api.endpoint.ImmutableEndpoint;
14  
15  import org.jivesoftware.smack.filter.AndFilter;
16  import org.jivesoftware.smack.filter.FromMatchesFilter;
17  import org.jivesoftware.smack.filter.MessageTypeFilter;
18  import org.jivesoftware.smack.filter.PacketFilter;
19  import org.jivesoftware.smack.packet.Message;
20  
21  /**
22   * {@link XmppConversation} implementation for sending normal Jabber messages.
23   */
24  public class XmppMessageConversation extends AbstractXmppConversation
25  {
26      public XmppMessageConversation(ImmutableEndpoint endpoint)
27      {
28          super(endpoint);
29      }
30  
31      @Override
32      protected PacketFilter createPacketFilter()
33      {
34          PacketFilter recipientFilter = new FromMatchesFilter(recipient);
35          PacketFilter messageTypeFilter = new MessageTypeFilter(Message.Type.normal);
36          return new AndFilter(recipientFilter, messageTypeFilter);
37      }
38      
39      public void dispatch(Message message)
40      {
41          message.setType(Message.Type.normal);
42          message.setTo(recipient);
43          
44          connection.sendPacket(message);
45      }
46  }