fipaos.util
Class DynamicClass


public class DynamicClass

This class provides dynamic access to methods of classes which may not be available at compile time & run time.


Constructor Summary
DynamicClass(String class_name, Class[] params, Object[] args)
          Creates an instance of the given class, using the constructor with the given arguments.
DynamicClass(String class_name)
          Creates an instance of the given class, using the default constructor.
DynamicClass(Object obj)
          Creates a DynamicClass to wrap the given Object

Method Summary
 static ObjectcreateInstance(String class_name)
          Instantiate an instance of a particular class
 static ObjectcreateInstance(String class_name, Class[] param_types, Object[] params)
          Instatiates a class, using a constructor with the given parameters
 ObjectgetObject()
           
 Objectinvoke(String method, Class[] params, Object[] args)
          Invokes a method on the wrapper object with the given arguments
 Objectinvoke(String method)
          Invokes a method on the wrapper object without any arguments
 static ObjectinvokeStatic(String class_name, String method, Class[] params, Object[] args)
          Invokes a method on the given object with the given arguments
 static ObjectinvokeStatic(String class_name, String method)
          Invokes a method on the given object with no arguments
 static voidmain(String[] args)
           
 StringtoString()
           

Constructor Detail

DynamicClass

public DynamicClass(String class_name, Class[] params, Object[] args)
throws java.lang.ClassNotFoundException,
java.lang.NoSuchMethodException,
java.lang.InstantiationException,
DynamicClassException
Creates an instance of the given class, using the constructor with the given arguments. NOTE: Primitive types (e.g. int, char, double) should be wrapped in their java.lang wrapper classes (e.g. Integer, Double etc...)
Parameters:
class_name - Name of the class to wrap
params - Argument signature for the constructor to use
args - Array containing parameters for constructor of class to wrap

DynamicClass

public DynamicClass(String class_name)
throws java.lang.ClassNotFoundException,
java.lang.NoSuchMethodException,
java.lang.InstantiationException,
DynamicClassException
Creates an instance of the given class, using the default constructor.
Parameters:
class_name - Name of the class to wrap
args - Array containing parameters for constructor of class to wrap

DynamicClass

public DynamicClass(Object obj)
Creates a DynamicClass to wrap the given Object
Parameters:
obj - Wrap the given object
Method Detail

createInstance

public static Object createInstance(String class_name)
Instantiate an instance of a particular class
Parameters:
class_name - Fully qualified name of the class to instantitate
Returns: An instance of the given class, or null if some error occured whilst instantiating an instance

createInstance

public static Object createInstance(String class_name, Class[] param_types, Object[] params)
Instatiates a class, using a constructor with the given parameters
Parameters:
class_name - Name of the class to instantiate
param_types - An array of the types of the parameters of the constructor to use
params - The actual parameters to the constructor
Returns: The instantiated object, or null if something went wrong

getObject

public Object getObject()

invoke

public Object invoke(String method, Class[] params, Object[] args)
throws DynamicClassException,
java.lang.NoSuchMethodException
Invokes a method on the wrapper object with the given arguments
Parameters:
method - The name of the method to invoke
params - Classes of arguments making up signature of method to invoke
args - An array of object to be used as arguments to the method being invoked (primitive types should be wrapped in appropriate Java classes (e.g. double => Double ).
Returns: The result of the operation, null if the method was void or an object wrapping the result if the return type is a primitive.

invoke

public Object invoke(String method)
throws DynamicClassException,
java.lang.NoSuchMethodException
Invokes a method on the wrapper object without any arguments
Parameters:
method - The name of the method to invoke
Returns: The result of the operation, null if the method was void or an object wrapping the result if the return type is a primitive.

invokeStatic

public static Object invokeStatic(String class_name, String method, Class[] params, Object[] args)
throws DynamicClassException,
java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException
Invokes a method on the given object with the given arguments
Parameters:
method - The name of the method to invoke
args - An array of object to be used as arguments to the method being invoked (primitive types should be wrapped in appropriate Java classes (e.g. double => Double ).
params - The classes of the arguments of the method to invoke
Returns: The result of the operation, null if the method was void or an object wrapping the result if the return type is a primitive.

invokeStatic

public static Object invokeStatic(String class_name, String method)
throws DynamicClassException,
java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException
Invokes a method on the given object with no arguments
Parameters:
method - The name of the method to invoke
Returns: The result of the operation, null if the method was void or an object wrapping the result if the return type is a primitive.

main

public static void main(String[] args)
throws java.lang.Throwable

toString

public String toString()

Association Links

to Class java.lang.Class

Class representing the wrapped object