Coverage Report - org.mule.transport.xmpp.XmppEndpointURIBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppEndpointURIBuilder
0%
0/16
0%
0/4
0
 
 1  
 /*
 2  
  * $Id: XmppEndpointURIBuilder.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.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  
  * This endpoint builder ensures that a path is set on the URI as the path is the message type.
 22  
  * 
 23  
  */
 24  0
 public class XmppEndpointURIBuilder extends UserInfoEndpointURIBuilder
 25  
 {
 26  
     @Override
 27  
     protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
 28  
     {
 29  0
         checkXmppMessageType(uri);
 30  0
         checkRecipient(uri);
 31  0
         super.setEndpoint(uri, props);
 32  0
     }
 33  
 
 34  
     private void checkXmppMessageType(URI uri) throws MalformedEndpointException
 35  
     {
 36  
         // the XMPP message type is stored in the host of the URL
 37  0
         String host = uri.getHost();
 38  
         
 39  0
         if (host.length() == 0)
 40  
         {
 41  0
             throw new MalformedEndpointException(XmppMessages.noMessageTypeInUri(), uri.toString());
 42  
         }
 43  
         
 44  
         try
 45  
         {
 46  0
             XmppMessageType.valueOf(host);
 47  
         }
 48  0
         catch (IllegalArgumentException e)
 49  
         {
 50  0
             throw new MalformedEndpointException(XmppMessages.invalidMessageTypeInUri(), 
 51  
                 uri.toString());
 52  0
         }
 53  0
     }
 54  
 
 55  
     private void checkRecipient(URI uri) throws MalformedEndpointException
 56  
     {
 57  
         // the recipient is stored in the path of the URL
 58  0
         if (uri.getPath().length() == 0)
 59  
         {
 60  0
             throw new MalformedEndpointException(XmppMessages.noRecipientInUri(), uri.toString());
 61  
         }        
 62  0
     }
 63  
 }