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

org.carrot2.util.resource.ContextClassLoaderLocator Maven / Gradle / Ivy

Go to download

Carrot2 search results clustering framework. Minimal functional subset (core algorithms and infrastructure, no document sources).

There is a newer version: 3.16.3
Show newest version

/*
 * 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() + "]";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy