tauZaman
v0.1

tauzaman
Class ClassLoaderMethodCaller

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--java.security.SecureClassLoader
              |
              +--java.net.URLClassLoader
                    |
                    +--tauzaman.ClassLoaderMethodCaller

public class ClassLoaderMethodCaller
extends java.net.URLClassLoader

ClassLoaderMethodCaller class dynamically loads a Class and provide service for calling any of loaded Methods.

Classes that will make use of ClassLoaderMethodCaller are;

See Also:
IrregularMapping, Calendar, FVFunction
Status:
Design complete, implementation not started

Field Summary
private  java.util.Hashtable methodsToClass
          A Hashtable, which maps methods of this CLMC to loaded classes.
 
Fields inherited from class java.net.URLClassLoader
 
Fields inherited from class java.security.SecureClassLoader
 
Fields inherited from class java.lang.ClassLoader
 
Constructor Summary
ClassLoaderMethodCaller(java.net.URL[] urls)
           Constructs a ClassLoaderMethodCaller object with specified URLs.
 
Method Summary
 java.lang.Object callMethod(java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Object[] args)
          Calls method with specified method name with specified actual parameters.
 void loadClass(java.lang.String className, java.lang.String methodName)
          Finds and loads the class with the specified name from the URL search path.
 java.lang.String toString()
          Returns string representation of method name - class name mapping of this ClassLoaderMethodCaller.
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, 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

methodsToClass

private java.util.Hashtable methodsToClass
A Hashtable, which maps methods of this CLMC to loaded classes.

Constructor Detail

ClassLoaderMethodCaller

public ClassLoaderMethodCaller(java.net.URL[] urls)

Constructs a ClassLoaderMethodCaller object with specified URLs. Any URL that ends with a '/' is assumed to refer to a directory. Otherwise, the URL is assumed to refer to a JAR file which will be downloaded and opened as needed.

Although constructor takes an array of URLs, we only use first URL in this array since urls in the system are always either contain a single class or point to a directory or a .jar file, which contain multiple classes.

Parameters:
urls - array of URLs
Method Detail

loadClass

public void loadClass(java.lang.String className,
                      java.lang.String methodName)
               throws DynamicLoadException
Finds and loads the class with the specified name from the URL search path. Method name is given for mapping purposes. If the class is already loaded then keep silent and use it.

Parameters:
className - name of the class to be searched and loaded
methodName - name of the method related to loaded class
Throws:
java.lang.Exception - if any abnormal condition occurs when loading a class, Exception may further be specialized
DynamicLoadException

callMethod

public java.lang.Object callMethod(java.lang.String methodName,
                                   java.lang.Class[] parameterTypes,
                                   java.lang.Object[] args)
                            throws DynamicLoadException
Calls method with specified method name with specified actual parameters. Returns return value of the method as an Object. Instance of the class that contains this method will be formed here.

Parameters:
methodName - name of the Method to be called
parameterTypes - the list of parameters. This is passed as a parameter instead of having fix names (which can also be done) to allow generality for a possible changes in future time.
args - the arguments used for the method call
Throws:
java.lang.Exception - if any abnormal condition occurs when loading a class, Exception may further be specialized
DynamicLoadException

toString

public java.lang.String toString()
Returns string representation of method name - class name mapping of this ClassLoaderMethodCaller.

Overrides:
toString in class java.lang.Object
Returns:
String string representation of this ClassLoaderMethodCaller

tauZaman
v0.1

Submit a bug or feature

tauZaman is an open-source, publicly avaliable project