View Javadoc

1   /*
2    * $Id: ResourceNameEndpointBuilder.java 7976 2007-08-21 14:26:13Z 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.impl.endpoint;
12  
13  import org.mule.umo.endpoint.MalformedEndpointException;
14  import org.mule.util.StringUtils;
15  
16  import java.net.URI;
17  import java.util.Properties;
18  
19  /**
20   * <code>ResourceNameEndpointBuilder</code> extracts a resource name from a uri
21   * endpointUri
22   * 
23   */
24  public class ResourceNameEndpointBuilder extends AbstractEndpointBuilder
25  {
26      public static final String RESOURCE_INFO_PROPERTY = "resourceInfo";
27  
28      protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
29      {
30          address = StringUtils.EMPTY;
31          if (uri.getHost() != null && !"localhost".equals(uri.getHost()))
32          {
33              address = uri.getHost();
34          }
35  
36          if (uri.getPath() != null && uri.getPath().length() != 0)
37          {
38              if (address.length() > 0)
39              {
40                  address += "/";
41              }
42              address += uri.getPath().substring(1);
43          }
44          else if (uri.getAuthority() != null && !uri.getAuthority().equals(address))
45          {
46              address += uri.getAuthority();
47          }
48          // is user info specified?
49          int y = address.indexOf("@");
50          if (y > -1)
51          {
52              this.userInfo = address.substring(0, y);
53          }
54          // increment to 0 or one char past the @
55          y++;
56  
57          int x = address.indexOf(":", y);
58          if (x > -1)
59          {
60              String resourceInfo = address.substring(y, x);
61              props.setProperty("resourceInfo", resourceInfo);
62              address = address.substring(x + 1);
63          }
64      }
65  }