/**
   * Executes the ldap delete operation.
   *
   * @param cf connection factory.
   * @param entryDns to delete
   * @throws Exception on any LDAP search error
   */
  protected void delete(final ConnectionFactory cf, final String[] entryDns) throws Exception {
    final Connection conn = cf.getConnection();
    conn.open();

    for (String dn : entryDns) {
      final DeleteOperation op = new DeleteOperation(conn);
      op.execute(new DeleteRequest(dn));
      System.out.println(String.format("Deleted entry: %s", dn));
    }
    conn.close();
  }
  /**
   * Executes the ldap add operation.
   *
   * @param cf connection factory
   * @param file to read ldif from
   * @throws Exception on any LDAP search error
   */
  protected void add(final ConnectionFactory cf, final String file) throws Exception {
    final Connection conn = cf.getConnection();
    conn.open();

    final LdifReader reader = new LdifReader(new FileReader(file));
    final LdapResult lr = reader.read();
    for (LdapEntry le : lr.getEntries()) {
      final AddOperation op = new AddOperation(conn);
      op.execute(new AddRequest(le.getDn(), le.getAttributes()));
      System.out.println(String.format("Added entry: %s", le));
    }
    conn.close();
  }