Ejemplo n.º 1
0
  public static ReadOnlyDriver getDriver(DriverManager dm, String prefix) {
    String[] names = dm.getDriverNames();
    for (int i = 0; i < names.length; i++) {
      Driver driver = dm.getDriver(names[i]);
      if (driver instanceof DBDriver) {
        DBDriver dbDriver = (DBDriver) driver;
        String[] prefixes = dbDriver.getPrefixes();
        for (String driverPrefix : prefixes) {
          if (driverPrefix.toLowerCase().equals(prefix.toLowerCase())) {
            return dbDriver;
          }
        }
      }
    }

    throw new DriverLoadException("No suitable driver for " + prefix);
  }
Ejemplo n.º 2
0
  public static ReadOnlyDriver getDriver(DriverManager dm, File file) {
    String[] names = dm.getDriverNames();
    for (int i = 0; i < names.length; i++) {
      Driver driver = dm.getDriver(names[i]);
      if (driver instanceof FileDriver) {
        FileDriver fileDriver = (FileDriver) driver;
        String[] extensions = fileDriver.getFileExtensions();
        for (String extension : extensions) {
          if (file.getAbsolutePath().toLowerCase().endsWith(extension.toLowerCase())) {
            return fileDriver;
          }
        }
      }
    }

    throw new DriverLoadException("No suitable driver for " + file.getAbsolutePath());
  }