FileDocCategorySizeDatePackage
LoaderUtils.javaAPI DocApache Ant 1.704466Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.util

LoaderUtils

public class LoaderUtils extends Object
ClassLoader utility methods

Fields Summary
private static final FileUtils
FILE_UTILS
Utilities used for file operations
Constructors Summary
Methods Summary
public static booleanclassExists(java.lang.ClassLoader loader, java.lang.String className)
Check if a classloader has a classname resource.

param
loader the classloader to look it.
param
className the name of the class to look for.
return
true if the classexists, false otherwise
since
Ant 1.7.0.

        return loader.getResource(classNameToResource(className)) != null;
    
public static java.lang.StringclassNameToResource(java.lang.String className)
Return the resource name of a class name.

param
className the name of the class to convert.
return
the corresponding resource name.
since
Ant 1.7.0.

        return className.replace('.", '/") + ".class";
    
public static java.io.FilegetClassSource(java.lang.Class c)
Find the directory or jar file the class has been loaded from.

param
c the class whose location is required.
return
the file or jar with the class or null if we cannot determine the location.
since
Ant 1.6

        return normalizeSource(Locator.getClassSource(c));
    
public static java.lang.ClassLoadergetContextClassLoader()
JDK1.1 compatible access to set the context class loader.

return
the ClassLoader instance being used as the context classloader on the current thread. Returns null on JDK 1.1

        Thread currentThread = Thread.currentThread();
        return currentThread.getContextClassLoader();
    
public static java.io.FilegetResourceSource(java.lang.ClassLoader c, java.lang.String resource)
Find the directory or a give resource has been loaded from.

param
c the classloader to be consulted for the source
param
resource the resource whose location is required.
return
the file with the resource source or null if we cannot determine the location.
since
Ant 1.6

        if (c == null) {
            c = LoaderUtils.class.getClassLoader();
        }
        return normalizeSource(Locator.getResourceSource(c, resource));
    
public static booleanisContextLoaderAvailable()
Indicates if the context class loader methods are available

return
true if the get and set methods dealing with the context classloader are available.

        return true;
    
private static java.io.FilenormalizeSource(java.io.File source)
Normalize a source location

param
source the source location to be normalized.
return
the normalized source location.

        if (source != null) {
            try {
                source = FILE_UTILS.normalize(source.getAbsolutePath());
            } catch (BuildException e) {
                // relative path
            }
        }

        return source;
    
public static voidsetContextClassLoader(java.lang.ClassLoader loader)
Set the context classloader

param
loader the ClassLoader to be used as the context class loader on the current thread.


                                  
         
        Thread currentThread = Thread.currentThread();
        currentThread.setContextClassLoader(loader);