View Javadoc

1   /*
2    * $Id: XmppConversationFactory.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.MuleRuntimeException;
14  import org.mule.api.endpoint.ImmutableEndpoint;
15  import org.mule.transport.xmpp.i18n.XmppMessages;
16  
17  /**
18   * A factory that creates {@link XmppConversation} instances based on the endpoint's configuration.
19   */
20  public class XmppConversationFactory
21  {
22      public XmppConversation create(ImmutableEndpoint endpoint)
23      {
24          String host = endpoint.getEndpointURI().getHost();
25          XmppMessageType type = XmppMessageType.valueOf(host);
26          
27          switch (type)
28          {
29              case MESSAGE:
30                  return createMessageConversation(endpoint);
31              
32              case CHAT:
33                  return createChatConversation(endpoint);
34  
35              case GROUPCHAT:
36                  return createGroupchatConversation(endpoint);
37          }                
38  
39          // we should never get here as valueOf on the enum above will choke if you pass
40          // in an invalid string
41          throw new MuleRuntimeException(XmppMessages.invalidConversationType(type));
42      }
43  
44      protected XmppConversation createMessageConversation(ImmutableEndpoint endpoint)
45      {
46          return new XmppMessageConversation(endpoint);
47      }
48  
49      protected XmppConversation createChatConversation(ImmutableEndpoint endpoint)
50      {
51          return new XmppChatConversation(endpoint);
52      }
53  
54      protected XmppConversation createGroupchatConversation(ImmutableEndpoint endpoint)
55      {
56          return new XmppMultiUserChatConversation(endpoint);
57      }
58  }
59  
60