package org.apache.logging.log4j.core.util;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;

public final class ClassLoaderResourceLoader implements ResourceLoader {
   private final ClassLoader loader;

   public ClassLoaderResourceLoader(ClassLoader loader) {
      this.loader = loader != null ? loader : this.getClass().getClassLoader();
   }

   public Class<?> loadClass(String name) throws ClassNotFoundException {
      return this.loader.loadClass(name);
   }

   public URL getResource(String name) {
      return this.loader.getResource(name);
   }

   public Enumeration<URL> getResources(String name) throws IOException {
      return this.loader.getResources(name);
   }

   public String toString() {
      return this.getClass().getCanonicalName() + '(' + this.loader.toString() + ')';
   }
}
