org.eclipse.actf.util.resources
Class ClassLoaderCache

java.lang.Object
  extended by org.eclipse.actf.util.resources.ClassLoaderCache

public class ClassLoaderCache
extends Object

cache for class loaders used during pre-instrumentation or transformation processes. The ACTF AOP engine uses the bootstrap classpath to perform .class file transformations and entries on this classpath cannot simultaneously occur on the standard classpath. Hence, any need for a Class object fo the former set of classes must be retreaved via this class. This cache should also be used to perform all class-comparison operations such as instanceof and isAssignableFrom.

Author:
Mike Squillace

Constructor Summary
protected ClassLoaderCache()
           
 
Method Summary
 Class classForName(String className)
          get a java.lang.Class object representing the named class
 ClassLoader getClassLoaderFor(String className)
          get the java.lang.ClassLoader reference for the named class.
static ClassLoaderCache getDefault()
          get the default cache or create one if one has not already been created
 URL getResource(String name)
          get a java.net.URL object representing the named resource
 Enumeration getResources(String name)
          get a java.util.Enumeration representing the named resources
 boolean isAssignableFrom(String className, Class testCls)
          test whether or not the given class is assignable to the specified class name.
 boolean isInstanceOf(String className, Object o)
          test whether or not the specified object is an instance of the class with the given name.
 boolean isNonAdvisableClassName(String classname)
          returns whether or not this class name names a class that cannot be instrumented in ACTF.
 void put(String className, ClassLoader cl)
          add a class name with its corresponding class loader to the cache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassLoaderCache

protected ClassLoaderCache()
Method Detail

getDefault

public static ClassLoaderCache getDefault()
get the default cache or create one if one has not already been created

Returns:
default cache

getResource

public URL getResource(String name)
get a java.net.URL object representing the named resource

Parameters:
resourceName - - name of desired resource
Returns:
java.net.URL object or null if name cannot be resolved

getResources

public Enumeration getResources(String name)
                         throws IOException
get a java.util.Enumeration representing the named resources

Parameters:
resourceName - - name of desired resource
Returns:
java.util.Enumeration object or null if name cannot be resolved
Throws:
IOException

classForName

public Class classForName(String className)
get a java.lang.Class object representing the named class

Parameters:
className - - name of desired class
Returns:
java.lang.Class object or null if name cannot be resolved

getClassLoaderFor

public ClassLoader getClassLoaderFor(String className)
get the java.lang.ClassLoader reference for the named class. The algorithm used by this method is as follows:

Note: This method is used by all other methods in this class to resolve class names.

Parameters:
className - name of class
Returns:
ClassLoader object for the class named or null if the name cannot be resolved

put

public void put(String className,
                ClassLoader cl)
add a class name with its corresponding class loader to the cache

Parameters:
className - - name of class
cl - - class loader

isAssignableFrom

public boolean isAssignableFrom(String className,
                                Class testCls)
test whether or not the given class is assignable to the specified class name.

Parameters:
className - name of class to which target is to be assigned
testCls - class to be tested
Returns:
true if and only if the test class is equal to or a subclass of the class name, false otherwise
See Also:
Class.isAssignableFrom(java.lang.Class)

isInstanceOf

public boolean isInstanceOf(String className,
                            Object o)
test whether or not the specified object is an instance of the class with the given name.

Parameters:
className - - name of class
o - - object to be tested
Returns:
true if and only if the object is an instance of hte class named by the className, false otherwise

isNonAdvisableClassName

public boolean isNonAdvisableClassName(String classname)
returns whether or not this class name names a class that cannot be instrumented in ACTF. Classes that cannot be instrumented include classes in the ACTF packages, the AOP engine classes, classes that comprise the XML parsing engines, etc.

Parameters:
classname - name of class to be tested
Returns:
true if class named by this class name can be instrumented, false otherwise