public static Environment getEnvironment(Object obj) {
    Environment env = null;

    // try to find an environment going up the class hierarchy
    if (obj != null && _environmentMap != null) {
      synchronized(_syncMonitor) {
        Object iterObj = obj;
          
        do {
          if (iterObj instanceof Class) {
            env     = (Environment)_environmentMap.get(new EnvironmentKey((Class)iterObj));
            iterObj = ((Class)iterObj).getSuperclass();
          } else {
            env = (Environment)_environmentMap.get(iterObj);
            iterObj = iterObj.getClass();
          }
          if (env != null) {
            break;
          }
        } while (iterObj instanceof Class);
      }
    }
    
    // not found ? Than take the default environment
    if (env == null) {
      synchronized(_syncMonitor) {
        if (_defaultEnvironment == null) {
          _defaultEnvironment = new DefaultEnvironment();
        }
        env = _defaultEnvironment;
      }
    }
    return env;
  }