/**
   * Retrieves the View instance with the given id.
   *
   * <p>Invokes {@link UifDictionaryIndex#getImmutableViewById(java.lang.String)} to get the view
   * singleton from spring then returns a copy.
   *
   * @param viewId the unique id for the view
   * @return View instance with the given id
   * @throws org.kuali.rice.krad.datadictionary.DataDictionaryException if view doesn't exist for id
   */
  public View getViewById(final String viewId) {
    // check for preloaded view
    if (viewPools.containsKey(viewId)) {
      final UifViewPool viewPool = viewPools.get(viewId);
      synchronized (viewPool) {
        if (!viewPool.isEmpty()) {
          View view = viewPool.getViewInstance();

          // replace view in the pool
          Runnable createView =
              new Runnable() {
                public void run() {
                  View newViewInstance = CopyUtils.copy(getImmutableViewById(viewId));
                  viewPool.addViewInstance(newViewInstance);
                }
              };

          Thread t = new Thread(createView);
          t.start();

          return view;
        } else {
          LOG.info(
              "Pool size for view with id: "
                  + viewId
                  + " is empty. Considering increasing max pool size.");
        }
      }
    }

    View view = getImmutableViewById(viewId);

    return CopyUtils.copy(view);
  }