|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2013 Brett Wooldridge
|
|
|
|
|
* Copyright (C) 2013, 2014 Brett Wooldridge
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -21,34 +21,12 @@ import java.util.HashSet;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Methods useful for class reflection and class loading.
|
|
|
|
|
*
|
|
|
|
|
* @author Brett Wooldridge
|
|
|
|
|
*/
|
|
|
|
|
public final class ClassLoaderUtils
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Get the class loader which can be used to generate proxies without leaking memory.
|
|
|
|
|
* @return the class loader which can be used to generate proxies without leaking memory.
|
|
|
|
|
*/
|
|
|
|
|
public static ClassLoader getClassLoader()
|
|
|
|
|
{
|
|
|
|
|
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
|
|
|
|
if (cl != null) {
|
|
|
|
|
return new CascadingClassLoader(cl);
|
|
|
|
|
}
|
|
|
|
|
return ClassLoaderUtils.class.getClassLoader();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Class<?> loadClass(String className) throws ClassNotFoundException
|
|
|
|
|
{
|
|
|
|
|
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
|
|
|
|
if (cl != null) {
|
|
|
|
|
return new CascadingClassLoader(cl).loadClass(className);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Class.forName(className);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Set<Class<?>> getAllInterfaces(Class<?> clazz)
|
|
|
|
|
{
|
|
|
|
|
Set<Class<?>> interfaces = new HashSet<Class<?>>();
|
|
|
|
@ -68,26 +46,4 @@ public final class ClassLoaderUtils
|
|
|
|
|
|
|
|
|
|
return interfaces;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class CascadingClassLoader extends ClassLoader
|
|
|
|
|
{
|
|
|
|
|
private ClassLoader contextLoader;
|
|
|
|
|
|
|
|
|
|
CascadingClassLoader(ClassLoader contextLoader)
|
|
|
|
|
{
|
|
|
|
|
this.contextLoader = contextLoader;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Class<?> findClass(String name) throws ClassNotFoundException
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return contextLoader.loadClass(name);
|
|
|
|
|
}
|
|
|
|
|
catch (ClassNotFoundException cnfe) {
|
|
|
|
|
return CascadingClassLoader.class.getClassLoader().loadClass(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|