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