private void initJNDI(Configuration configuration) throws TorqueException {
    log.debug("Starting initJNDI");

    Configuration c = configuration.subset(JNDI_KEY);
    if (c == null || c.isEmpty()) {
      throw new TorqueException("JndiDataSourceFactory requires a jndi "
        + "path property to lookup the DataSource in JNDI.");
    }

    try {
      Hashtable env = new Hashtable();
      for (Iterator i = c.getKeys(); i.hasNext();) {
        String key = (String) i.next();
        if (key.equals(PATH_KEY)) {
          path = c.getString(key);
          if (log.isDebugEnabled()) {
            log.debug("JNDI path: " + path);
          }
        } else if (key.equals(TIME_BETWEEN_LOOKUPS_KEY)) {
          ttl = c.getLong(key, ttl);
          if (log.isDebugEnabled()) {
            log.debug("Time between context lookups: " + ttl);
          }
        } else {
          String value = c.getString(key);
          env.put(key, value);
          if (log.isDebugEnabled()) {
            log.debug("Set jndi property: " + key + "=" + value);
          }
        }
      }

      ctx = new InitialContext(env);
      log.debug("Created new InitialContext");
      debugCtx(ctx);
    } catch (Exception e) {
      log.error("", e);
      throw new TorqueException(e);
    }
  }