org.carrot2.util.resource.ContextClassLoaderLocator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of carrot2-mini Show documentation
Show all versions of carrot2-mini Show documentation
Carrot2 search results clustering framework. Minimal functional subset
(core algorithms and infrastructure, no document sources).
/*
* Carrot2 project.
*
* Copyright (C) 2002-2019, Dawid Weiss, Stanisław Osiński.
* All rights reserved.
*
* Refer to the full license file "carrot2.LICENSE"
* in the root folder of the repository checkout or at:
* http://www.carrot2.org/carrot2.LICENSE
*/
package org.carrot2.util.resource;
/**
* Looks up resources in the thread's context class loader.
*/
public final class ContextClassLoaderLocator implements IResourceLocator
{
/**
*
*/
@Override
public IResource [] getAll(String resource)
{
ClassLoader cl = getCCL();
if (cl != null)
{
return ClassLoaderLocator.getAll(cl, resource);
}
return new IResource [0];
}
private ClassLoader getCCL() {
try
{
return Thread.currentThread().getContextClassLoader();
}
catch (SecurityException e)
{
// Not available.
return null;
}
}
@Override
public int hashCode()
{
return 0xbebe;
}
@Override
public boolean equals(Object target)
{
if (target == this) return true;
if (target != null && target instanceof ContextClassLoaderLocator)
{
return true;
}
return false;
}
@Override
public String toString()
{
return this.getClass().getName() + " [current: " + getCCL() + "]";
}
}