public OfficeManager buildOfficeManager() throws IllegalStateException {
    if (officeHome == null)
      throw new IllegalStateException("officeHome not set and could not be auto-detected");
    else if (!officeHome.isDirectory())
      throw new IllegalStateException(
          "officeHome doesn't exist or is not a directory: " + officeHome);
    else if (!OfficeUtils.getOfficeExecutable(officeHome).isFile())
      throw new IllegalStateException(
          "invalid officeHome: it doesn't contain soffice.bin: " + officeHome);
    if (templateProfileDir != null && !isValidProfileDir(templateProfileDir))
      throw new IllegalStateException(
          "templateProfileDir doesn't appear to contain a user profile: " + templateProfileDir);
    if (!workDir.isDirectory())
      throw new IllegalStateException("workDir doesn't exist or is not a directory: " + workDir);

    if (processManager == null) processManager = findBestProcessManager();

    final int numInstances =
        connectionProtocol == OfficeConnectionProtocol.PIPE ? pipeNames.length : portNumbers.length;
    final UnoUrl[] unoUrls = new UnoUrl[numInstances];
    for (int i = 0; i < numInstances; i++)
      unoUrls[i] =
          connectionProtocol == OfficeConnectionProtocol.PIPE
              ? UnoUrl.pipe(pipeNames[i])
              : UnoUrl.socket(portNumbers[i]);
    return new ProcessPoolOfficeManager(
        officeHome,
        unoUrls,
        runAsArgs,
        templateProfileDir,
        workDir,
        retryTimeout,
        taskQueueTimeout,
        taskExecutionTimeout,
        maxTasksPerProcess,
        processManager,
        manageExternalInstances);
  }