}
@Override
public void removeClassLoader(DeploymentUnit unit) throws Exception
{
Module module = unit.getAttachment(Module.class);
if (module == null)
return;
ClassLoader classLoader = unit.getClassLoader();
if (classLoader instanceof InterceptionClassLoader)
{
InterceptionClassLoader icl = (InterceptionClassLoader)classLoader;
classLoader = icl.getDelegate();
}
try
{
try
{
// Remove the classloader
getSystem().unregisterClassLoader(classLoader);
}
finally
{
// Try to tidy up empty domains
String domainName = module.getDeterminedDomainName();
if (ClassLoaderSystem.DEFAULT_DOMAIN_NAME.equals(domainName) == false)
{
ClassLoaderDomain domain = getSystem().getDomain(domainName);
if (domain.hasClassLoaders() == false)
getSystem().unregisterDomain(domain);
}
}
}
finally
{
cleanup(unit, module);
module.reset();
}
}