protected void arrangeLists(ActionContext actionContext) throws GTClientException {
    try {
      ConnectionSetupResultAForm form = (ConnectionSetupResultAForm) actionContext.getActionForm();
      // IGTConnectionSetupResultEntity result =
      // (IGTConnectionSetupResultEntity)getEntity(actionContext);
      Short status = form.getStatusShort();
      if (IGTConnectionSetupResultEntity.STATUS_SUCCESS.equals(status)) {
        OperationContext opCon = OperationContext.getOperationContext(actionContext.getRequest());
        List gridMasterList = (List) opCon.getAttribute(GRIDMASTER_LIST);
        if (gridMasterList == null)
          throw new NullPointerException("gridMasterList (inOpCon"); // 20030422AH
        List routerList = (List) opCon.getAttribute(ROUTER_LIST);
        if (routerList == null)
          throw new NullPointerException("routerList (in opCon)"); // 20030422AH

        StaticUtils.arrangeList(gridMasterList, form.getAvailableGridMastersOrder());
        StaticUtils.arrangeList(routerList, form.getAvailableRoutersOrder());

        form.setAvailableGridMastersOrder(StaticUtils.initialOrderString(gridMasterList.size()));
        form.setAvailableRoutersOrder(StaticUtils.initialOrderString(routerList.size()));
      }
    } catch (Throwable t) {
      throw new GTClientException(
          "Error processing order of availableRouters and availableGridMasters", t);
    }
  }
  protected void prepLists(ActionContext actionContext, boolean reloaded) throws GTClientException {
    try {
      OperationContext opCon = OperationContext.getOperationContext(actionContext.getRequest());
      List gridMasterList = (List) opCon.getAttribute(GRIDMASTER_LIST);
      if (reloaded || (gridMasterList == null)) {
        IGTConnectionSetupResultEntity result =
            (IGTConnectionSetupResultEntity) getEntity(actionContext);
        gridMasterList =
            (List) result.getFieldEntities(IGTConnectionSetupResultEntity.AVAILABLE_GRIDMASTERS);
        List routerList =
            (List) result.getFieldEntities(IGTConnectionSetupResultEntity.AVAILABLE_ROUTERS);
        if (gridMasterList == null)
          throw new NullPointerException("gridMasterList is null"); // 20030422AH
        if (routerList == null) throw new NullPointerException("routerList is null"); // 20030422AH
        opCon.setAttribute(GRIDMASTER_LIST, gridMasterList);
        opCon.setAttribute(ROUTER_LIST, routerList);

        ConnectionSetupResultAForm form =
            (ConnectionSetupResultAForm) actionContext.getActionForm();
        String initRoutersOrder = StaticUtils.initialOrderString(routerList.size());
        String initMastersOrder = StaticUtils.initialOrderString(gridMasterList.size());
        form.setAvailableGridMastersOrder(initMastersOrder);
        form.setAvailableRoutersOrder(initRoutersOrder);
      }
    } catch (Throwable t) {
      throw new GTClientException(
          "Error prepping GridMaster and Router lists in OperationContext", t);
    }
  }
  protected void updateEntityFields(ActionContext actionContext, IGTEntity entity)
      throws GTClientException {
    ConnectionSetupResultAForm form = (ConnectionSetupResultAForm) actionContext.getActionForm();
    IGTConnectionSetupResultEntity result = (IGTConnectionSetupResultEntity) entity;
    IGTConnectionSetupParamEntity param =
        (IGTConnectionSetupParamEntity)
            result.getFieldValue(IGTConnectionSetupResultEntity.SETUP_PARAMETERS);

    Short status = form.getStatusShort();
    if (IGTConnectionSetupResultEntity.STATUS_FAILURE.equals(status)
        || IGTConnectionSetupResultEntity.STATUS_NOT_DONE.equals(status)) {
      param.setFieldValue(
          IGTConnectionSetupParamEntity.ORIGINAL_LOCATION, form.getOriginalLocation());
      param.setFieldValue(
          IGTConnectionSetupParamEntity.SERVICING_ROUTER, form.getServicingRouter());
      param.setFieldValue(
          IGTConnectionSetupParamEntity.SECURITY_PASSWORD, form.getSecurityPassword());
    } else if (IGTConnectionSetupResultEntity.STATUS_SUCCESS.equals(status)) {
      OperationContext opCon = OperationContext.getOperationContext(actionContext.getRequest());
      List gridMasterList = (List) opCon.getAttribute(GRIDMASTER_LIST);
      List routerList = (List) opCon.getAttribute(ROUTER_LIST);
      Collection gridMasterUids = StaticCtrlUtils.getUids(gridMasterList);
      Collection routerUids = StaticCtrlUtils.getUids(routerList);
      result.setFieldValue(IGTConnectionSetupResultEntity.AVAILABLE_GRIDMASTERS, gridMasterUids);
      result.setFieldValue(IGTConnectionSetupResultEntity.AVAILABLE_ROUTERS, routerUids);
    } else {
      throw new java.lang.IllegalStateException(
          "Illegal STATUS for connectionSetupResult:" + status);
    }
  }
  /**
   * Obtain the ImportSchema entity from the previous entity.
   *
   * @param actionContext
   * @return
   * @throws GTClientException
   */
  private IGTImportSchemaEntity getImportSchema(ActionContext actionContext)
      throws GTClientException {
    try {
      OperationContext opContext = OperationContext.getOperationContext(actionContext.getRequest());
      OperationContext parentOpContext = opContext.getPreviousContext();
      if (parentOpContext == null) {
        throw new java.lang.NullPointerException("null parent OperationContext reference");
      }
      IGTImportSchemaEntity importSchema =
          (IGTImportSchemaEntity) parentOpContext.getAttribute(IOperationContextKeys.ENTITY);
      if (importSchema == null) {
        throw new java.lang.NullPointerException(
            "No entity object found in parent OperationContext");
      }
      if (!(importSchema instanceof IGTImportSchemaEntity)) {
        throw new java.lang.IllegalStateException(
            "Entity found in parent OperationContext is"
                + " not a IGTImportSchemaEntity entity. Entity="
                + importSchema);
      }

      return importSchema;
    } catch (Exception ex) {
      throw new GTClientException(
          "[SchemaMappingFileDispatchAction.getImportSchema] Error retrieving ImportSchema entity from previous OperationContext",
          ex);
    }
  }
  /** instead of save the entity into backend, we save it in to the importSchema entity */
  @Override
  protected void saveWithManager(ActionContext actionContext, IGTManager manager, IGTEntity entity)
      throws GTClientException {
    try {
      OperationContext op = OperationContext.getOperationContext(actionContext.getRequest());
      String index =
          (String)
              op.getAttribute(
                  INDEX_KEY); // It can be used to differentiate whether we are saving a new entity
                              // or an existing one
      // I followed the existing implementation, so didn't use boolean.

      IGTImportSchemaEntity importSchema = getImportSchema(actionContext);
      ArrayList schemaMappingList =
          (ArrayList) importSchema.getFieldValue(IGTImportSchemaEntity.SCHEMA_MAPPING);

      if ("new".equals(index)) {
        schemaMappingList.add(entity);
      }
    } catch (Exception ex) {
      throw new GTClientException(
          "[SchemaMappingFileDispatchAction.saveWithManager] Error perfroming saving in ImportSchema entity",
          ex);
    }
  }
  /** Override super class method to perform additional population for Operation Context */
  @Override
  protected void processPreparedOperationContext(
      ActionContext actionContext, OperationContext opContext) throws GTClientException {
    try {
      IGTSchemaMappingFileEntity entity = null;
      String indexString = actionContext.getRequest().getParameter("index");
      opContext.setAttribute(INDEX_KEY, indexString); // so that when we save the entity,
      // we can differentiate whether we are saving
      // a new entity or an existing entity. (see detail in saveWithManager)

      if (indexString != null) {
        if (!indexString.equals("new")) {
          try {
            int index = Integer.parseInt(indexString);
            IGTImportSchemaEntity importSchema = getImportSchema(actionContext);
            ArrayList schemaMappingList =
                (ArrayList) importSchema.getFieldValue(IGTImportSchemaEntity.SCHEMA_MAPPING);
            if (schemaMappingList == null) {
              throw new NullPointerException(
                  "[SchemaMappingFileDispatchAction.processPreparedOperationContext] Null value for schemaMappingList.");
            }
            try {
              entity = (IGTSchemaMappingFileEntity) schemaMappingList.get(index);
            } catch (Throwable t) {
              throw new GTClientException(
                  "[SchemaMappingFileDispatchAction.processPreparedOperationContext] Error retrieving schemaMappingFile entity from list at index "
                      + index,
                  t);
            }
            if (entity == null) {
              throw new java.lang.NullPointerException(
                  "[SchemaMappingFileDispatchAction.processPreparedOperationContext] Null entity object at index "
                      + index
                      + " of schemaMappingList list retrieved from ImportSchema entity "
                      + importSchema);
            }
          } catch (Throwable t) {
            throw new GTClientException(
                "[SchemaMappingFileDispatchAction.processPreparedOperationContext] Error retrieving schemaMappingFile entity object from"
                    + " importSchema entity in parent OperationContext",
                t);
          }
        } else {
          entity = (IGTSchemaMappingFileEntity) getRequestedEntity(actionContext);
        }
      } else {
        throw new GTClientException(
            "[SchemaMappingFileDispatchAction.processPreparedOperationContext]No index specified");
      }
      opContext.setAttribute(IOperationContextKeys.ENTITY, entity);
      ActionForward submitForward = actionContext.getMapping().findForward("submit");
      opContext.setAttribute(IOperationContextKeys.FORM_SUBMIT_URL, submitForward.getPath());
    } catch (Exception ex) {
      throw new GTClientException(
          "[SchemaMappingFileDispatchAction.processPreparedOperationContext] Error obtaining SchemaMappingFile entity object",
          ex);
    }
  }
  protected void processPreparedOperationContext(
      ActionContext actionContext, OperationContext opContext) throws GTClientException {
    IGTConnectionSetupResultEntity entity = null;
    IGTSession gtasSession = getGridTalkSession(actionContext);
    IGTConnectionSetupResultManager manager =
        (IGTConnectionSetupResultManager)
            gtasSession.getManager(IGTManager.MANAGER_CONNECTION_SETUP_RESULT);
    entity = manager.getConnectionSetupResult();
    if (entity == null) {
      throw new GTClientException("No connectionSetupResult entity to update");
    }

    opContext.setAttribute(IOperationContextKeys.ENTITY, entity);
    ActionForward submitForward = actionContext.getMapping().findForward("submit");
    opContext.setAttribute(IOperationContextKeys.FORM_SUBMIT_URL, submitForward.getPath());
  }