com.bea.jvm
Interface ClassLibrary

All Superinterfaces:
Describable, JVMComponent

public interface ClassLibrary
extends JVMComponent

Interface to query and monitor the JVM's set of currently loaded classes and their classloaders.

Author:
Calle Wilund, Marcus Hirt

Method Summary
 void addClassLoadListener(java.lang.ClassLoader loader, ClassLoadListener listener)
          Add a listener to receive event notification of Class load/unload.
 void addClassLoadListener(ClassLoadListener listener)
          Adds a listener to receive event notification of any Class load/unload.
 java.util.Collection getAllClasses()
          Find all classes in the JVM (will search through all class loaders, but will not load Classes.)
 java.util.Collection getAllClasses(java.lang.ClassLoader loader)
          Deprecated. This function (for historical reasons) includes only classes defined by the specified ClassLoader, but the name is rather unspecific. Use @link {#getDeclaredClasses(ClassLoader) getDeclaredClasses} or @link {#getInitiatedClasses(ClassLoader) getInitiatedClasses instead.
 java.util.Collection getAllClasses(java.lang.String className)
          Find all classes with this name in the JVM (will search through all class loaders, but will not load the Class if not found.)
 java.util.Collection getAllClassLoaders()
          Returns all the ClassLoaders currently in use.
 java.lang.Class getClass(java.lang.String className, java.lang.ClassLoader loader)
          Find an already loaded class in the JVM.
 java.lang.Class getClass(java.lang.String className, java.lang.ClassLoader loader, boolean load)
          Find a named class in the JVM.
 ClassPreProcessor getClassPreProcessor()
          Returns the ClassPreProcessor currently in use.
 java.util.Collection getDeclaredClasses(java.lang.ClassLoader loader)
          Find all non-array classes declared by this loader.
 java.util.Collection getInitiatedClasses(java.lang.ClassLoader loader)
          Find all non-array classes for which the loader wsa recorded as initiating loader.
 void redefineClass(java.lang.Class cl, byte[] buffer, int offset, int length)
          Redefines the specified class.
 void removeClassLoadListener(ClassLoadListener listener)
          Removes the specified ClassLoadListener.
 void setClassPreProcessor(ClassPreProcessor preProcessor)
          Registers a class preprocessor.
 
Methods inherited from interface com.bea.jvm.JVMComponent
getJVM
 
Methods inherited from interface com.bea.jvm.Describable
getDescription
 

Method Detail

getAllClassLoaders

java.util.Collection getAllClassLoaders()
                                        throws NotAvailableException
Returns all the ClassLoaders currently in use.

Returns:
all java.lang.ClassLoaders currently in the system.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.
See Also:
ClassLoader

getClass

java.lang.Class getClass(java.lang.String className,
                         java.lang.ClassLoader loader,
                         boolean load)
                         throws NotAvailableException,
                                java.lang.ClassNotFoundException
Find a named class in the JVM.

Parameters:
className - the fully qualified name of the class.
loader - the ClassLoader to search in (will include all parent loaders also).
load - whether to initiate a Class load if the class is not already loaded.
Returns:
the class matching the the parameters above.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.
java.lang.ClassNotFoundException - if the class can't be found using the specified ClassLoader, or if either the loader or name is null.
See Also:
Class

getClass

java.lang.Class getClass(java.lang.String className,
                         java.lang.ClassLoader loader)
                         throws NotAvailableException,
                                java.lang.ClassNotFoundException
Find an already loaded class in the JVM.

Parameters:
className - the fully qualified name of the class.
loader - the ClassLoader to search in (will include all parent loaders also).
Returns:
the class mathing the name, and that is loaded in the specified ClassLoader.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.
java.lang.ClassNotFoundException - if either the name or the loader is null.
See Also:
Class

getAllClasses

java.util.Collection getAllClasses()
                                   throws NotAvailableException
Find all classes in the JVM (will search through all class loaders, but will not load Classes.) Will only return the classes from the defining class loaders, i.e. there will be no duplicates.

Returns:
all classes in the JVM.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.
See Also:
Class

getAllClasses

java.util.Collection getAllClasses(java.lang.String className)
                                   throws NotAvailableException,
                                          java.lang.ClassNotFoundException
Find all classes with this name in the JVM (will search through all class loaders, but will not load the Class if not found.) Will only return the classes from the defining class loaders, i.e. there will be no duplicates.

Parameters:
className - the fully qualified name of the class.
Returns:
all classes in the JVM matching the specified name.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.
java.lang.ClassNotFoundException - if the argument is null, or if the class can't be found.
See Also:
Class

getAllClasses

java.util.Collection getAllClasses(java.lang.ClassLoader loader)
                                   throws NotAvailableException
Deprecated. This function (for historical reasons) includes only classes defined by the specified ClassLoader, but the name is rather unspecific. Use @link {#getDeclaredClasses(ClassLoader) getDeclaredClasses} or @link {#getInitiatedClasses(ClassLoader) getInitiatedClasses instead.

Find all (loaded) classes in this loader (will _not_ include parent loaders). This method throws a NullPointerException if the argument is null.

Parameters:
loader - the ClassLoader to search.
Returns:
all the classes loaded in the specified ClassLoader.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.
See Also:
Class, ClassLoader

getDeclaredClasses

java.util.Collection getDeclaredClasses(java.lang.ClassLoader loader)
                                        throws NotAvailableException
Find all non-array classes declared by this loader. (null signifies the bootstrap loader).

Parameters:
loader - the ClassLoader to search.
Returns:
all non-array and non-primitive classes declared by the specified ClassLoader.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.
See Also:
Class, ClassLoader

getInitiatedClasses

java.util.Collection getInitiatedClasses(java.lang.ClassLoader loader)
                                         throws NotAvailableException
Find all non-array classes for which the loader wsa recorded as initiating loader. (null signifies the bootstrap loader).

Parameters:
loader - the ClassLoader to search.
Returns:
all non-array and non-primitive classes initiated by the specified ClassLoader.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.
See Also:
Class, ClassLoader

addClassLoadListener

void addClassLoadListener(java.lang.ClassLoader loader,
                          ClassLoadListener listener)
                          throws NotAvailableException
Add a listener to receive event notification of Class load/unload. If either of the argument is null, a NullPointerException will be thrown.

Parameters:
loader - the ClassLoader on which we want to listen.
listener - the event listener to add.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.

addClassLoadListener

void addClassLoadListener(ClassLoadListener listener)
                          throws NotAvailableException
Adds a listener to receive event notification of any Class load/unload. This method throws a NullPointerException if the argument is null.

Parameters:
listener - the listener to add.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.

removeClassLoadListener

void removeClassLoadListener(ClassLoadListener listener)
                             throws NotAvailableException
Removes the specified ClassLoadListener. If the argument is null, the request is going to be ignored. This method throws a NullPointerException if the argument is null.

Parameters:
listener - the ClassLoadListener to stop receiving class load events.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.

redefineClass

void redefineClass(java.lang.Class cl,
                   byte[] buffer,
                   int offset,
                   int length)
                   throws NotAvailableException,
                          ClassRedefinitionException
Redefines the specified class. This method throws a NullPointerException if the class or byte buffer is null. It throws ArrayIndexOutOfBounds if either offset or length are wrong.

Parameters:
cl - the class to be redefined.
buffer - the byte buffer containing the bytecode for the new version of the class.
offset - the offset to start reading from.
length - the length to read.
Throws:
ClassRedefinitionException - if the transform could not be completed due to an illegal transform (error in the supplied bytecode). Note that this is an unchecked (Runtime) exception; it will not be verified by the compiler!
NullPointerException if either class or byte buffer is null.
ArrayIndexOutOfBoundsException if either offset or length mismatch.
NotAvailableException if this functionality isn't available in this JVM. This exception will be thrown by JRockit versions earlier than Ariane.
NotAvailableException

setClassPreProcessor

void setClassPreProcessor(ClassPreProcessor preProcessor)
                          throws NotAvailableException
Registers a class preprocessor. The preprocessor may redefine all byte buffers from which the vm will create a class, i.e, it is called after ClassLoader.defineClass, but before the actual class is created in the virtual machine.

NOTE: Only one (1) preprocessor can be active in the system at any time. If a client needs to chain preprocessors, this should be done by wrapping, i.e. getting the previous preprocessor and explicitly calling it either before or after the preprocessing is done.

If preProcessor is null, any previously registered preprocessor is removed.

Parameters:
preProcessor - a ClassPreProcessor to recieve callbacks on class definitions.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.
See Also:
getClassPreProcessor(), ClassPreProcessor

getClassPreProcessor

ClassPreProcessor getClassPreProcessor()
                                       throws NotAvailableException
Returns the ClassPreProcessor currently in use. Returns null if no ClassPreProcessor is in use.

Returns:
the ClassPreProcessor currently in use.
Throws:
NotAvailableException - if this functionality isn't available in this JVM.
See Also:
ClassPreProcessor


Copyright © 2006 BEA Systems Inc.