| java.lang.Object org.griphyn.common.util.DynamicLoader
DynamicLoader | public class DynamicLoader (Code) | | This class provides a dynamic class loading facility. It is
tightly coupled to the property facility. To dynamically obtain
an instance of a class through its constructor:
Integer i = null;
DynamicLoader dl = new DynamicLoader( "java.lang.Integer" );
try {
// instantiate as Integer("42")
String arg[] = new String[1];
arg[0] = "42";
i = (Integer) dl.instantiate(arg);
} catch ( Exception e ) {
System.err.println( dl.convertException(e) );
System.exit(1);
}
Similarily, to obtain an instance of a class through a static
method provided by the same class, or another class:
Integer i = null;
DynamicLoader dl = new DynamicLoader( "java.lang.Integer" );
try {
// instantiate as Integer("42")
String arg[] = new String[1];
arg[0] = "42";
i = (Integer) dl.static_method( "valueOf", arg );
} catch ( Exception e ) {
System.err.println( dl.convertException(e) );
System.exit(1);
}
author: Karan Vahi author: Jens-S. Vöckler version: $Revision: 50 $ |
Method Summary | |
public static String | convertException(String classname, Exception e) Converts an exception from the class loader into an error message.
Parameters: classname - is the name or some other class signifier. Parameters: e - is the exception thrown by the class loader. | public String | convertException(Exception e) Converts an exception from the class loader into an error message.
Parameters: e - is the exception thrown by the class loader. | public static String | convertExceptionToString(String classname, Throwable e) Converts an exception from the class loader into an error message.
Note: It does not convert any cause messages.
Parameters: classname - is the name or some other class signifier. Parameters: e - is the exception thrown by the class loader. | public String | getClassName() Obtains the fully-qualified class name that this instance works with. | public Object | instantiate(Object[] arguments) Dynamically instantiates a class from a contructor. | public Object | instantiate(Class[] classes, Object[] arguments) Dynamically instantiates a class from a contructor. | public void | setClassName(String classname) Sets the fully-qualified class name to load. | public Object | static_method(String method, Object[] arguments) Dynamically instantiates a class from a static method which
constructs the resulting object. |
convertException | public static String convertException(String classname, Exception e)(Code) | | Converts an exception from the class loader into an error message.
Parameters: classname - is the name or some other class signifier. Parameters: e - is the exception thrown by the class loader. a string that tries to describe what went wrong. |
convertException | public String convertException(Exception e)(Code) | | Converts an exception from the class loader into an error message.
Parameters: e - is the exception thrown by the class loader. a string that tries to describe what went wrong. |
convertExceptionToString | public static String convertExceptionToString(String classname, Throwable e)(Code) | | Converts an exception from the class loader into an error message.
Note: It does not convert any cause messages.
Parameters: classname - is the name or some other class signifier. Parameters: e - is the exception thrown by the class loader. a string that tries to describe what went wrong. |
instantiate | public Object instantiate(Class[] classes, Object[] arguments) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException(Code) | | Dynamically instantiates a class from a contructor. You must have
set the class name before invoking this method. Please note that
any exceptions thrown by the constructor will be wrapped into a
InvocationTargetException .
This method should be invoked, if the constructor declares
interface types as formal arguments, but the actual arguments
are implementation classes.
Parameters: classes - is a vector of the classes involved. Each itemin the classes vector matches the item in the arguments vector.The classes vector will be used to select the correct constructor.Please use "new Class[0]" for the argumentless default ctor. Parameters: arguments - are arguments to the constructor of the classto load. Please use "new Object[0]" for the argumentless defaultconstructor. an instance that must be cast to the correct class. exception: ClassNotFoundException - if the driver for the databasecannot be loaded. You might want to check your CLASSPATH, too. exception: NoSuchMethodException - if the driver's constructor interfacedoes not comply with the database driver API. exception: IllegalArgumentException - is thrown, if the number ofarguments do not match the number of types, ie the vector havemismatching sizes. exception: InstantiationException - if the driver class is an abstractclass instead of a concrete implementation. exception: IllegalAccessException - if the constructor for the driverclass it not publicly accessible to this package. exception: InvocationTargetException - if the constructor of the driverthrows an exception while being dynamically loaded. exception: SQLException - if the driver for the database can beloaded, but faults when initially accessing the database See Also: DynamicLoader.setClassName(String) |
static_method | public Object static_method(String method, Object[] arguments) throws ClassNotFoundException, SecurityException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, NullPointerException, IllegalArgumentException(Code) | | Dynamically instantiates a class from a static method which
constructs the resulting object. You must have set the class name
before invoking this method. Please note that any exceptions thrown
by the constructor will be wrapped into a
InvocationTargetException .
Parameters: method - is the name of the static method to call. Parameters: arguments - are arguments to the constructor of the classto load. Please use "new Object[0]" for the argumentless defaultconstructor. an instance that must be cast to the correct class. exception: ClassNotFoundException - if the driver for the databasecannot be loaded. You might want to check your CLASSPATH, too. exception: NoSuchMethodException - if the driver's constructor interfacedoes not comply with the database driver API. exception: InstantiationException - if the driver class is an abstractclass instead of a concrete implementation. exception: IllegalAccessException - if the constructor for the driverclass it not publicly accessible to this package. exception: InvocationTargetException - if the constructor of the driverthrows an exception while being dynamically loaded. exception: SQLException - if the driver for the database can beloaded, but faults when initially accessing the database exception: SecurityException - if you are not permitted to invoke themethod, or even list the methods provided by the class. exception: NullPointerException - if the method name isnull . exception: IllegalArgumentException - if the number of actual andformal parameter differ, unwrapping a primitive type failed, ora parameter value cannot be converted to the formal argument type. See Also: DynamicLoader.setClassName(String) |
|
|