static public URL getResource()

in src/main/java/org/apache/log4j/helpers/Loader.java [87:137]


  static public URL getResource(String resource) {
    ClassLoader classLoader = null;
    URL url = null;
    
    try {
  	if(!java1 && !ignoreTCL) {
  	  classLoader = getTCL();
  	  if(classLoader != null) {
  	    LogLog.debug("Trying to find ["+resource+"] using context classloader "
  			 +classLoader+".");
  	    url = classLoader.getResource(resource);      
  	    if(url != null) {
  	      return url;
  	    }
  	  }
  	}
  	
  	// We could not find resource. Ler us now try with the
  	// classloader that loaded this class.
  	classLoader = Loader.class.getClassLoader(); 
  	if(classLoader != null) {
  	  LogLog.debug("Trying to find ["+resource+"] using "+classLoader
  		       +" class loader.");
  	  url = classLoader.getResource(resource);
  	  if(url != null) {
  	    return url;
  	  }
  	}
    } catch(IllegalAccessException t) {
        LogLog.warn(TSTR, t);
    } catch(InvocationTargetException t) {
        if (t.getTargetException() instanceof InterruptedException
                || t.getTargetException() instanceof InterruptedIOException) {
            Thread.currentThread().interrupt();
        }
        LogLog.warn(TSTR, t);
    } catch(Throwable t) {
      //
      //  can't be InterruptedException or InterruptedIOException
      //    since not declared, must be error or RuntimeError.
      LogLog.warn(TSTR, t);
    }
    
    // Last ditch attempt: get the resource from the class path. It
    // may be the case that clazz was loaded by the Extentsion class
    // loader which the parent of the system class loader. Hence the
    // code below.
    LogLog.debug("Trying to find ["+resource+
  		   "] using ClassLoader.getSystemResource().");
    return ClassLoader.getSystemResource(resource);
  }