/*
   * (non-Javadoc)
   * @see sif3.infra.rest.env.ClientEnvironmentManager#createOrUpdateEnvironment(sif3.infra.common.model.EnvironmentType)
   */
  public EnvironmentType createOrUpdateEnvironment(
      EnvironmentType inputEnvironment, TokenInfo tokenInfo) {
    setSIF3Session(envOps.createOrUpdateSession(inputEnvironment, tokenInfo));
    if (getSIF3Session() != null) // creation was successful
    {
      // Extract the service info and store it in an easy accessible way in the session.
      SIFSessionUtils.loadServiceInfoForSession(getSIF3Session(), inputEnvironment);
      populateInfrastructureURLs(inputEnvironment);

      // XML no longer needed.
      getSIF3Session().setEnvironmentXML(null);

      return inputEnvironment;
    } else {
      return null; // error already logged.
    }
  }
  /*
   * (non-Javadoc)
   * @see sif3.infra.rest.env.ClientEnvironmentManager#reloadSessionFromFromWorkstore(sif3.common.model.EnvironmentKey)
   */
  public EnvironmentType reloadSessionFromFromWorkstore(EnvironmentKey environmentKey)
      throws IllegalArgumentException, PersistenceException {
    setSIF3Session(envOps.loadSession(environmentKey));
    if (getSIF3Session() != null) // session exists and was loaded successfully
    {
      // Extract the service info and store it in an easy accessible way in the session.
      EnvironmentType environment =
          envOps.loadEnvironmentFromString(getSIF3Session().getEnvironmentXML());
      SIFSessionUtils.loadServiceInfoForSession(getSIF3Session(), environment);
      populateInfrastructureURLs(environment);

      // XML no longer needed.
      getSIF3Session().setEnvironmentXML(null);

      return environment;
    } else {
      return null; // error already logged.
    }
  }