private void initDataSource(Configuration configuration) throws TorqueException {
    log.debug("Starting initDataSource");
    try {
      Object dataSource = null;

      Configuration c = configuration.subset(DATASOURCE_KEY);
      if (c != null) {
        for (Iterator i = c.getKeys(); i.hasNext();) {
          String key = (String) i.next();
          if (key.equals(CLASSNAME_KEY)) {
            String classname = c.getString(key);
            if (log.isDebugEnabled()) {
              log.debug("Datasource class: " + classname);
            }

            Class dsClass = Class.forName(classname);
            dataSource = dsClass.newInstance();
          } else {
            if (dataSource != null) {
              if (log.isDebugEnabled()) {
                log.debug("Setting datasource property: " + key);
              }
              setProperty(key, c, dataSource);
            } else {
              log.error("Tried to set property " + key
                + " without Datasource definition!");
            }
          }
        }
      }

      if (dataSource != null) {
        bindDStoJndi(ctx, path, dataSource);
      }
    } catch (Exception e) {
      log.error("", e);
      throw new TorqueException(e);
    }
  }