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.jdbc;
8   
9   import org.mule.api.endpoint.MalformedEndpointException;
10  import org.mule.endpoint.AbstractEndpointURIBuilder;
11  
12  import java.net.URI;
13  import java.util.Properties;
14  
15  /**
16   * Parses a JDBC style endpoint to a MuleEndpointURI
17   */
18  public class JdbcEndpointURIBuilder extends AbstractEndpointURIBuilder
19  {
20  
21      protected void setEndpoint(URI uri, Properties props) throws MalformedEndpointException
22      {
23          if (uri.getHost() != null && !"localhost".equals(uri.getHost()))
24          {
25              endpointName = uri.getHost();
26          }
27          int i = uri.getPath().indexOf("/", 1);
28          if (i > 0)
29          {
30              endpointName = uri.getPath().substring(1, i);
31              address = uri.getPath().substring(i + 1);
32          }
33          else if (uri.getPath() != null && uri.getPath().length() != 0)
34          {
35              address = uri.getPath().substring(1);
36          }
37          else
38          {
39              address = uri.getAuthority();
40          }
41          // JDBC endpoints can just have a param string, hence te address is left
42          // null, but the address
43          // should always be a non-null value
44          if (address == null)
45          {
46              address = uri.getScheme();
47          }
48      }
49  }