class AttachmentManager implements Lifecycle {

  public void attachAdapterToVehicle(@Nonnull String vehicleName,
                                     @Nonnull VehicleCommAdapterFactory factory) {
    requireNonNull(vehicleName, "vehicleName");
    requireNonNull(factory, "factory");

    VehicleEntry vehicleEntry = vehicleEntryPool.getEntryFor(vehicleName);
    if (vehicleEntry == null) {
      LOG.warn("No vehicle entry found for '{}'. Entries: {}",
               vehicleName,
               vehicleEntryPool);
      return;
    }

    detachAdapterFromVehicle(vehicleName, true);

    VehicleCommAdapter commAdapter = factory.getAdapterFor(vehicleEntry.getVehicle());
    if (commAdapter == null) {
      LOG.warn("Factory {} did not provide adapter for vehicle {}, ignoring.",
               factory,
               vehicleEntry.getVehicle().getName());
      return;
    }

    commAdapter.initialize();
    controllerPool.attachVehicleController(vehicleEntry.getVehicle().getName(), commAdapter);

    vehicleEntry.setCommAdapterFactory(factory);
    vehicleEntry.setCommAdapter(commAdapter);
    vehicleEntry.setProcessModel(commAdapter.getProcessModel());

    objectService.updateObjectProperty(vehicleEntry.getVehicle().getReference(),
                                       Vehicle.PREFERRED_ADAPTER,
                                       factory.getClass().getName());

    updateAttachmentInformation(vehicleEntry);
  }

  @Inject public  AttachmentManager(@Nonnull TCSObjectService objectService,
                           @Nonnull LocalVehicleControllerPool controllerPool,
                           @Nonnull VehicleCommAdapterRegistry commAdapterRegistry,
                           @Nonnull VehicleEntryPool vehicleEntryPool,
                           @Nonnull @ApplicationEventBus EventHandler eventHandler,
                           @Nonnull KernelApplicationConfiguration configuration);

}