com.github.ansell.restletutils.CompositeClassLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of restlet-utils Show documentation
Show all versions of restlet-utils Show documentation
Utilities for use with Restlet
The newest version!
package com.github.ansell.restletutils;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/**
* Original source: https://gist.github.com/1945491
*
* Chained classloaders that are necessary to use restlet to pull resources out of a jar file
*
* @author Peter Ansell [email protected]
*/
public class CompositeClassLoader extends ClassLoader
{
private List classLoaders = new ArrayList();
public void addClassLoader(final ClassLoader cl)
{
this.classLoaders.add(cl);
}
@Override
public URL getResource(final String name)
{
for(final ClassLoader cl : this.classLoaders)
{
final URL resource = cl.getResource(name);
if(resource != null)
{
return resource;
}
}
return null;
}
@Override
public InputStream getResourceAsStream(final String name)
{
for(final ClassLoader cl : this.classLoaders)
{
final InputStream resource = cl.getResourceAsStream(name);
if(resource != null)
{
return resource;
}
}
return null;
}
@Override
public Class> loadClass(final String name, final boolean resolve) throws ClassNotFoundException
{
for(final ClassLoader cl : this.classLoaders)
{
try
{
return cl.loadClass(name);
}
catch(final ClassNotFoundException ex)
{
}
}
throw new ClassNotFoundException(name);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy