View Javadoc

1   /*
2    * $Id: XmppEndpointURIBuilder.java 10489 2008-01-23 17:53:38Z dfeist $
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.transport.xmpp;
12  
13  import org.mule.api.endpoint.MalformedEndpointException;
14  import org.mule.endpoint.UserInfoEndpointURIBuilder;
15  import org.mule.transport.xmpp.i18n.XmppMessages;
16  
17  import java.net.URI;
18  import java.util.Properties;
19  
20  /**
21   * Does the same as the UserInfoEndpointBuilder but also ensures that a path is set
22   * on the uri. The path is used as either the groupChat name or the recipient name of
23   * a one on one chat.
24   */
25  public class XmppEndpointURIBuilder extends UserInfoEndpointURIBuilder
26  {
27      protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
28      {
29          if (uri.getPath().length() == 0)
30          {
31              throw new MalformedEndpointException(XmppMessages.noRecipientInUri(), uri.toString());
32          }
33          if (props.getProperty(XmppConnector.XMPP_GROUP_CHAT, "false").equalsIgnoreCase("true"))
34          {
35              if (props.getProperty(XmppConnector.XMPP_NICKNAME, null) == null)
36              {
37                  throw new MalformedEndpointException(XmppMessages.nicknameMustBeSet(), uri.toString());
38              }
39          }
40          super.setEndpoint(uri, props);
41      }
42  }