private @Nullable Object findInstance(RemoteCall call, Class<?> clazz) {
    if (call instanceof ServiceCall) {
      Object projectInstance = null;
      Ref projectRef = ((ServiceCall)call).getProjectRef();
      if (projectRef != null) {
        projectInstance = getReference(call.getSessionId(), projectRef.id());
      }

      Class<?> serviceClass = clazz;
      String serviceInterface = ((ServiceCall)call).getServiceInterface();
      if (serviceInterface != null) {
        serviceClass = findServiceInterface(clazz, serviceInterface);
        if (serviceClass == null) {
          throw new DriverIlligalStateException("Unable to find interface " + serviceInterface + " for service " + clazz);
        }
      }

      Object instance;
      if (projectInstance instanceof Project) {
        instance = ((Project)projectInstance).getService(serviceClass);
        if (instance == null) {
          instance = ((Project)projectInstance).getServices(serviceClass, ClientKind.CONTROLLER).get(0);
        }
      }
      else {
        instance = ApplicationManager.getApplication().getService(serviceClass);
        if (instance == null) {
          instance = ApplicationManager.getApplication().getServices(serviceClass, ClientKind.CONTROLLER).get(0);
        }
      }
      return instance;
    }

    if (call instanceof RefCall) {
      Ref ref = ((RefCall)call).getRef();
      Object reference = getReference(call.getSessionId(), ref.id());

      if (reference == null) throw new DriverIlligalStateException("No such ref exists " + ref);

      return reference;
    }

    if (call instanceof UtilityCall) {
      return null;
    }

    throw new UnsupportedOperationException("Unsupported call type " + call);
  }
private @Nullable Object findInstance(RemoteCall call, Class<?> clazz)