private void checkSqlException(SQLException e) {
   if (e.getMessage().contains("FATAL: no pg_hba.conf entry for host")
       && e.getMessage().contains("template1")) { // $NON-NLS-1$ //$NON-NLS-2$
     // this is understandable the template1 database is not accessible to this user/location so it
     // is not an error
   } else if (e.getMessage().contains("FATAL: role")
       && e.getMessage().contains("does not exist")) { // $NON-NLS-1$//$NON-NLS-2$
     // this is understandable the template1 database is not accessible to this user/location so it
     // is not an error
     result = "Username or password is incorrect";
   } else {
     PostgisPlugin.log("Error connecting to database template1", e);
     result = "Unrecognized connection failure.  Check parameters and database.";
   }
 }
  public PostgisService2 createService(URL id, Map<String, Serializable> params) {
    try {
      if (getFactory() == null || !getFactory().isAvailable()) {
        return null; // factory not available
      }
      if (!getFactory().canProcess(params)) {
        return null; // the factory cannot use these parameters
      }
    } catch (Exception unexpected) {
      if (Platform.inDevelopmentMode()) {
        // this should never happen
        PostgisPlugin.log(
            "PostGISExtension canProcess errored out with: " + unexpected, unexpected);
      }
      return null; // the factory cannot really use these parameters
    }
    if (reasonForFailure(params) != null) {
      return null;
    }
    Map<String, Serializable> params2 = params;

    ensurePortIsInt(params2);

    try {
      URL finalID = DIALECT.toURL(params2);
      Pair<Map<String, Serializable>, String> split = processParams(params2);
      if (split.getRight() != null) {
        return null;
      }

      return new PostgisService2(finalID, split.getLeft());
    } catch (MalformedURLException e) {
      PostgisPlugin.log("Unable to construct proper service URL.", e); // $NON-NLS-1$
      return null;
    }
  }
  public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

    try {

      Map<String, Serializable> params = new HashMap<String, Serializable>();
      // XXX _p3:
      // params.put( DBTYPE.key, (Serializable) new PostgisServiceDialect().dbType );
      params.put(HOST.key, host);
      params.put(PORT.key, port);
      params.put(USER.key, username);
      params.put(PASSWD.key, password);
      params.put(DATABASE.key, "template1");

      BasicDataSource source = PostgisServiceExtension2.getFactory().createDataSource(params);
      Connection connection = source.getConnection();
      try {

        Statement statement = connection.createStatement();
        if (statement.execute("SELECT datname FROM pg_database")) {
          ResultSet resultSet = statement.getResultSet();
          while (resultSet.next()) {
            databaseNames.add(resultSet.getString("datname"));
          }
        }
        statement.close();
      } finally {
        if (connection != null) {
          connection.close();
        }
        if (source != null) {
          source.close();
        }
      }
    } catch (SQLException e) {
      checkSqlException(e);
    } catch (IOException e) {
      if (e.getCause() instanceof SQLException) {
        checkSqlException((SQLException) e.getCause());
      } else {
        PostgisPlugin.log("Error connecting to datasource", e);
        result = "Unrecognized connection failure.  Check parameters and database.";
      }
    }
    ran = true;
  }