uk.ac.cam.cl.ijam
Class Module

java.lang.Object
  extended by java.lang.ClassLoader
      extended by uk.ac.cam.cl.ijam.Module

final class Module
extends java.lang.ClassLoader

Module instance of a module definition. As in the Java Module System, module instances are implemented with classloaders. Module classloader loads classes in self-parent-self fashion. It collaborates with the classloaders of the imported module instances to give the desired iJAM semantics.

If the user specified the compatiblity mode in Runtime, this class will give LJAM's classloading semantics instead.

See Also:
ModuleDefinition, Runtime

Field Summary
private  java.util.Map<Module,java.util.Map<java.lang.String,java.lang.String>> imports
           
private  org.apache.bcel.classfile.JavaClass javaClass
           
private  ModuleDefinition md
           
private static java.lang.String sep
           
 
Constructor Summary
Module(ModuleDefinition md, java.util.Map<Module,java.util.Map<java.lang.String,java.lang.String>> imports)
           
 
Method Summary
(package private)  void execute(java.lang.String mainClass)
          Starts execution in the context of this module instance.
private  byte[] getBytes(java.lang.String filename)
          This function simply reads the specified classfile, and returns its raw bytes.
 java.lang.Class<?> loadClass(java.lang.String name)
           
private  java.lang.Class<?> loadClassInSelf(java.lang.String name)
          This function is used to load a class from the contents of the current module instance.
private  java.lang.Class<?> renameClass(java.lang.Class<?> cl, java.lang.String name)
          This function renames a loaded class to match the request.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, 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, toString, wait, wait, wait
 

Field Detail

sep

private static final java.lang.String sep

md

private final ModuleDefinition md

imports

private final java.util.Map<Module,java.util.Map<java.lang.String,java.lang.String>> imports

javaClass

private org.apache.bcel.classfile.JavaClass javaClass
Constructor Detail

Module

Module(ModuleDefinition md,
       java.util.Map<Module,java.util.Map<java.lang.String,java.lang.String>> imports)
Method Detail

execute

void execute(java.lang.String mainClass)
Starts execution in the context of this module instance. In particular, it does the following:
  1. loads the specified class with its own classloader;
  2. locates and invokes class's main method (execution happens under classloader that loaded the class);
  3. when execution stops, the thread's classloader is automatically reset to its original value.
    1. Parameters:
      mainClass - The name of the class to execute.

getBytes

private byte[] getBytes(java.lang.String filename)
                 throws java.io.IOException
This function simply reads the specified classfile, and returns its raw bytes.

Parameters:
filename - The name of the classfile to read.
Returns:
Raw bytes of the file found.
Throws:
java.io.IOException - Occurs if file could not be read.

renameClass

private java.lang.Class<?> renameClass(java.lang.Class<?> cl,
                                       java.lang.String name)
This function renames a loaded class to match the request.

Parameters:
cl - The class to rename.
name - The name to rename to.
Returns:
Renamed class.

loadClass

public java.lang.Class<?> loadClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Overrides:
loadClass in class java.lang.ClassLoader
Throws:
java.lang.ClassNotFoundException

loadClassInSelf

private java.lang.Class<?> loadClassInSelf(java.lang.String name)
This function is used to load a class from the contents of the current module instance.

Parameters:
name - FQN of the class to load.
Returns:
The loaded class, or null of not found.