All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.core.ContextClassLoader Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.core;

public class ContextClassLoader extends ClassLoader {
   
   private final Class type;
   
   public ContextClassLoader(Class type) {
      this.type = type;
   }

   @Override
   public Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
      ClassLoader loader = type.getClassLoader();
      
      try{
         return loader.loadClass(name);
      } catch(ClassNotFoundException cause) {
         Thread thread = Thread.currentThread();
         ClassLoader context = thread.getContextClassLoader();
         
         if(context != loader) {
            return context.loadClass(name);
         }
         throw cause;
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy