Exemplo n.º 1
0
  /**
   * Create a new file database with the specified name and unique folder name.
   *
   * @param displayName name displayed to the user
   * @param name of the file database used when creating the dabase in the file system.
   * @param path of the file database
   * @return the created file database
   * @throws LocationAlreadyExistsException - if the location already exists
   */
  public DefaultFileDatabase createFileDatabase(
      String displayName, String name, String path, String description)
      throws LocationAlreadyExistsException {

    if (path == null) {
      throw new IllegalStateException("The path cannot be null");
    }

    if (name == null) {
      throw new IllegalStateException("the name cannot be null");
    }

    // create the new file database
    DefaultFileDatabase FileDatabaseImpl = new DefaultFileDatabase();
    FileDatabaseImpl.setDisplayName(displayName);
    FileDatabaseImpl.setName(name);
    FileDatabaseImpl.setPath(path);
    FileDatabaseImpl.setFileServer(this);

    // create a folder for this file database
    FileSystemManager.createDirectory(FileDatabaseImpl.getFullPath());

    fileDatabases.add(FileDatabaseImpl);
    return FileDatabaseImpl;
  }
Exemplo n.º 2
0
  /**
   * Rename the file database.
   *
   * @param oldName - old name of the file database
   * @param name - new name to give the file database.
   * @return true if the the file database is renamed.
   */
  public boolean renameFileDatabase(String currentName, String newName) {
    boolean renamed = false;
    DefaultFileDatabase fd = getFileDatabase(currentName);
    if (fileDatabases.contains(fd)) {

      // make sure the new folder name does not exist
      File f = new File(fd.getPath() + newName.trim());
      if (!f.exists()) {
        if (!FileSystemManager.renameFile(
            new File(fd.getFullPath()), new File(fd.getPath() + newName))) {
          throw new IllegalStateException("Could not rename file");
        }
        fileDatabases.remove(fd);
      }
      fd.setName(newName);
      fileDatabases.add(fd);

      renamed = true;
    }

    return renamed;
  }