public String removeDomain(String domainId) throws Exception {
    try {
      startTransaction(false);

      // Remove the domain
      getOrganization().domain.removeDomain(idAsInt(domainId));
      if (domainDriverInstances.get(domainId) != null) {
        domainDriverInstances.remove(domainId);
      }
      this.commit();
      LoginPasswordAuthentication.initDomains();

      return domainId;
    } catch (AdminException e) {
      try {
        this.rollback();
      } catch (Exception e1) {
        SilverTrace.error("admin", "DomainDriverManager.createDomain", "root.EX_ERR_ROLLBACK", e1);
      }
      throw new AdminException(
          "DomainDriverManager.createDomain",
          SilverpeasException.ERROR,
          "admin.EX_ERR_ADD_DOMAIN",
          "domain id: '" + domainId + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
  }
  /**
   * @param sKey anthentication key
   * @param removeKey remove after
   * @return
   * @throws Exception
   */
  public Map<String, String> authenticate(String sKey, boolean removeKey) throws Exception {
    Map<String, String> loginDomainId = new HashMap<String, String>();
    try {
      startTransaction(false);

      // Get the domain information
      KeyStoreRow ksr = getOrganization().keyStore.getRecordByKey(idAsInt(sKey));
      if (ksr == null) {
        throw new AdminException(
            "DomainDriverManager.authenticate",
            SilverpeasException.ERROR,
            "admin.EX_ERR_KEY_NOT_FOUND",
            "key: '" + sKey + "'");
      }

      loginDomainId.put("login", ksr.login);
      loginDomainId.put("domainId", idAsString(ksr.domainId));

      // Remove key from keytore in database
      if (removeKey) {
        getOrganization().keyStore.removeKeyStoreRecord(idAsInt(sKey));
      }

      // Commit transaction
      commit();
      return loginDomainId;
    } catch (AdminPersistenceException e) {
      try {
        this.rollback();
      } catch (Exception e1) {
        SilverTrace.error("admin", "DomainDriverManager.authenticate", "root.EX_ERR_ROLLBACK", e1);
      }
      throw new AdminException(
          "DomainDriverManager.authenticate",
          SilverpeasException.ERROR,
          "admin.EX_ERR_AUTHENTICATE",
          "key: '" + sKey + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
  }
  public String updateDomain(Domain theDomain) throws Exception {
    try {
      startTransaction(false);

      DomainRow dr = new DomainRow();
      dr.id = idAsInt(theDomain.getId());
      dr.name = theDomain.getName();
      dr.description = theDomain.getDescription();
      dr.className = theDomain.getDriverClassName();
      dr.propFileName = theDomain.getPropFileName();
      dr.authenticationServer = theDomain.getAuthenticationServer();
      dr.theTimeStamp = theDomain.getTheTimeStamp();
      dr.silverpeasServerURL = theDomain.getSilverpeasServerURL();

      // Create domain
      getOrganization().domain.updateDomain(dr);
      if (domainDriverInstances.get(theDomain.getId()) != null) {
        domainDriverInstances.remove(theDomain.getId());
      }
      this.commit();
      LoginPasswordAuthentication.initDomains();

      return theDomain.getId();
    } catch (AdminException e) {
      try {
        this.rollback();
      } catch (Exception e1) {
        SilverTrace.error("admin", "DomainDriverManager.updateDomain", "root.EX_ERR_ROLLBACK", e1);
      }
      throw new AdminException(
          "DomainDriverManager.updateDomain",
          SilverpeasException.ERROR,
          "admin.EX_ERR_ADD_DOMAIN",
          "domain name: '" + theDomain.getName() + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
  }
  /**
   * @param domainId
   * @return DomainDriver
   */
  public DomainDriver getDomainDriver(int domainId) throws Exception {
    DomainDriver domainDriver = null;
    boolean osAllocated = false;
    try {
      domainDriver = domainDriverInstances.get(idAsString(domainId));
      if (domainDriver == null) {
        // Set the OrganizationSchema (if not already done)
        getOrganizationSchema();
        osAllocated = true;

        // Get the domain information
        DomainRow dr = getOrganization().domain.getDomain(domainId);
        if (dr == null) {
          throw new AdminException(
              "DomainDriverManager.getDomainDriver",
              SilverpeasException.ERROR,
              "admin.EX_ERR_DOMAIN_NOT_FOUND",
              "domain Id: '" + domainId + "'");
        }

        // Get the driver class name
        try {
          domainDriver = DomainDriverFactory.getDriver(dr.className);
          domainDriver.init(domainId, dr.propFileName, dr.authenticationServer);
        } catch (ClassNotFoundException e) {
          throw new AdminException(
              "DomainDriverManager.getDomainDriver",
              SilverpeasException.ERROR,
              "root.EX_CLASS_NOT_FOUND",
              e);
        } catch (IllegalAccessException e) {
          throw new AdminException(
              "DomainDriverManager.getDomainDriver",
              SilverpeasException.ERROR,
              "root.EX_ILLEGAL_ACCESS",
              e);
        } catch (InstantiationException e) {
          throw new AdminException(
              "DomainDriverManager.getDomainDriver",
              SilverpeasException.ERROR,
              "root.EX_INSTANTIATION",
              e);
        }

        // Save DomainDriver instance
        domainDriverInstances.put(idAsString(domainId), domainDriver);
      }
    } catch (AdminPersistenceException e) {
      throw new AdminException(
          "DomainDriverManager.getDomainDriver",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_DOMAIN_DRIVER",
          "domain id: '" + domainId + "'",
          e);
    } finally {
      if (osAllocated) {
        releaseOrganizationSchema();
      }
    }
    return domainDriver;
  }