org.objectweb.easybeans.loader
Class EasyBeansClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.objectweb.easybeans.loader.EasyBeansClassLoader

public class EasyBeansClassLoader
extends java.net.URLClassLoader

This class defines the EasyBeans classloader. This classloader allows to set the bytecode for a given class. Then, when the class will be loaded, it will define the class by using the associated bytecode.

Author:
Florent Benoit

Field Summary
private  java.lang.reflect.Method defineClassMethod
          Method of the classloader allowing to define some classes.
private  java.lang.Class javaLangClassLoaderClass
          java.lang.ClassLoader class.
private static JLog logger
          Logger.
private  java.util.Map<java.lang.String,byte[]> mapDefined
          Map between class name and the bytecode associated to the given classname.
private  boolean recomputeToString
          Need to recompute toString() value ? (urls have changed) True by default (not done).
private  java.lang.String toStringValue
          String representation used by toString() method.
 
Constructor Summary
EasyBeansClassLoader(java.net.URL[] urls)
          Use the same constructors as parent class.
EasyBeansClassLoader(java.net.URL[] urls, java.lang.ClassLoader parent)
          Use the same constructors as parent class.
 
Method Summary
 void addClassDefinition(java.lang.String className, byte[] bytecode)
          Adds the bytecode for a given class.
private  void computeToString()
          Compute a string representation used by toString() method.
private  java.lang.Class<?> defineInternalClass(java.lang.String className, byte[] bytecode)
          Defines the class by using the bytecode of the given classname.
protected  java.lang.Class<?> findClass(java.lang.String name)
          Finds and loads the class with the specified name from the URL search path.
 java.lang.Class<?> loadClass(java.lang.String name)
          When trying to load a class, look if this class needs to be defined.
private  java.lang.Class searchingDefinedClass(java.lang.String className)
          Search a class in the local repository of classes to define.
 java.lang.String toString()
          Displays useful information.
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static JLog logger
Logger.


recomputeToString

private boolean recomputeToString
Need to recompute toString() value ? (urls have changed) True by default (not done). Then, compute is done only when required and if needed


toStringValue

private java.lang.String toStringValue
String representation used by toString() method.


javaLangClassLoaderClass

private java.lang.Class javaLangClassLoaderClass
java.lang.ClassLoader class.


defineClassMethod

private java.lang.reflect.Method defineClassMethod
Method of the classloader allowing to define some classes.


mapDefined

private java.util.Map<java.lang.String,byte[]> mapDefined
Map between class name and the bytecode associated to the given classname.

Constructor Detail

EasyBeansClassLoader

public EasyBeansClassLoader(java.net.URL[] urls,
                            java.lang.ClassLoader parent)
Use the same constructors as parent class.

Parameters:
urls - the URLs from which to load classes and resources
parent - the parent class loader for delegation

EasyBeansClassLoader

public EasyBeansClassLoader(java.net.URL[] urls)
Use the same constructors as parent class.

Parameters:
urls - the URLs from which to load classes and resources
Method Detail

findClass

protected java.lang.Class<?> findClass(java.lang.String name)
                                throws java.lang.ClassNotFoundException
Finds and loads the class with the specified name from the URL search path. If this classloader has the bytecode for the associated class, it defines the class.

Overrides:
findClass in class java.net.URLClassLoader
Parameters:
name - the name of the class
Returns:
the resulting class
Throws:
java.lang.ClassNotFoundException - if the class could not be found

defineInternalClass

private java.lang.Class<?> defineInternalClass(java.lang.String className,
                                               byte[] bytecode)
Defines the class by using the bytecode of the given classname.

Parameters:
className - the name of the class.
bytecode - the bytes of the given class.
Returns:
the class which is now defined

addClassDefinition

public void addClassDefinition(java.lang.String className,
                               byte[] bytecode)
Adds the bytecode for a given class. It will be used when class will be loaded.

Parameters:
className - the name of the class.
bytecode - the bytes of the given class.

loadClass

public java.lang.Class<?> loadClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
When trying to load a class, look if this class needs to be defined.

Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
name - the class name to load.
Returns:
the class if it was found.
Throws:
java.lang.ClassNotFoundException - if the class is not found.

searchingDefinedClass

private java.lang.Class searchingDefinedClass(java.lang.String className)
Search a class in the local repository of classes to define.

Parameters:
className - the name of the class to search and define if found.
Returns:
the class if it was defined and loaded.

toString

public java.lang.String toString()
Displays useful information.

Overrides:
toString in class java.lang.Object
Returns:
information

computeToString

private void computeToString()
Compute a string representation used by toString() method.