Coverage Report - org.mule.endpoint.ResourceNameEndpointURIBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
ResourceNameEndpointURIBuilder
68%
21/31
50%
14/28
9
 
 1  
 /*
 2  
  * $Id: ResourceNameEndpointURIBuilder.java 12140 2008-06-24 13:11:34Z dirk.olmes $
 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.endpoint;
 12  
 
 13  
 import org.mule.api.endpoint.MalformedEndpointException;
 14  
 import org.mule.util.StringUtils;
 15  
 
 16  
 import java.net.URI;
 17  
 import java.util.Properties;
 18  
 
 19  
 import org.apache.commons.logging.Log;
 20  
 import org.apache.commons.logging.LogFactory;
 21  
 
 22  
 /**
 23  
  * <code>ResourceNameEndpointBuilder</code> extracts a resource name from a uri
 24  
  * endpointUri
 25  
  * 
 26  
  */
 27  486
 public class ResourceNameEndpointURIBuilder extends AbstractEndpointURIBuilder
 28  
 {
 29  
 
 30  2
     protected static final Log logger = LogFactory.getLog(ResourceNameEndpointURIBuilder.class);
 31  
     
 32  
     public static final String RESOURCE_INFO_PROPERTY = "resourceInfo";
 33  
 
 34  
     protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
 35  
     {
 36  486
         address = StringUtils.EMPTY;
 37  486
         String host = uri.getHost();
 38  486
         if (host != null && !"localhost".equals(host))
 39  
         {
 40  474
             address = host;
 41  
         }
 42  
 
 43  486
         String path = uri.getPath();
 44  486
         String authority = uri.getAuthority();
 45  
         
 46  486
         if (path != null && path.length() != 0)
 47  
         {
 48  0
             if (address.length() > 0)
 49  
             {
 50  0
                 address += "/";
 51  
             }
 52  0
             address += path.substring(1);
 53  
         }
 54  486
         else if (authority != null && !authority.equals(address))
 55  
         {
 56  12
             address += authority;
 57  
             
 58  12
             int atCharIndex = -1;
 59  12
             if (address != null && address.length() != 0 && ((atCharIndex = address.indexOf("@")) > -1))
 60  
             {
 61  0
                 userInfo = address.substring(0, atCharIndex);
 62  0
                 address = address.substring(atCharIndex + 1);
 63  
             }
 64  
 
 65  
         }
 66  
         
 67  
         // is user info specified?
 68  486
         int y = address.indexOf("@");
 69  486
         if (y > -1)
 70  
         {
 71  0
             userInfo = address.substring(0, y);
 72  
         }
 73  
         // increment to 0 or one char past the @
 74  486
         y++;
 75  
 
 76  486
         String credentials = uri.getUserInfo();
 77  486
         if (credentials != null && credentials.length() != 0)
 78  
         {
 79  0
             userInfo = credentials;
 80  
         }
 81  
         
 82  486
         int x = address.indexOf(":", y);
 83  486
         if (x > -1)
 84  
         {
 85  0
             String resourceInfo = address.substring(y, x);
 86  0
             props.setProperty("resourceInfo", resourceInfo);
 87  0
             address = address.substring(x + 1);
 88  
         }
 89  486
     }
 90  
 }