org.opensha.commons.util
Class ClassUtils

java.lang.Object
  extended by org.opensha.commons.util.ClassUtils

public class ClassUtils
extends Object

Title: ClassUtils

Description: Utility class comprised of static methods for creating classes dynamically at runtime. This means, given the full package class name as a String, this utility class can create an object instance. This allows for adding new classes at runtime and they can be instantiated without recompiling the code. This is real useful for the IMR Tester Applet. A picklist of IMRs are presented in the GUI. Once a user makes a selection, the IMR class name is obtained and the class created at runtime via this utility package.

Version:
1.0
Author:
Steven W. Rock

Constructor Summary
ClassUtils()
           
 
Method Summary
static Object createNoArgConstructorClassInstance(ArrayList params, ArrayList paramTypes, String className)
          Dynamically creates the class instance using the constructor with arguments.
static Object createNoArgConstructorClassInstance(String className)
          Dynamically creates the class instance with no argument constructor.
static String getClassNameWithoutPackage(Class<?> theClass)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtils

public ClassUtils()
Method Detail

createNoArgConstructorClassInstance

public static Object createNoArgConstructorClassInstance(String className)
Dynamically creates the class instance with no argument constructor. Creates a class instance from a string of the full class name including packages. This is how you dynamically make objects at runtime if you don't know which\ class beforehand. For example, if you wanted to create a BJF_1997_AttenRel you can do it the normal way:

BJF_1997_AttenRel imr = new BJF_1997_AttenRel()

If your not sure the user wants this one or AS_1997_AttenRel you can use this function instead to create the same class by:

BJF_1997_AttenRel imr = (BJF_1997_AttenRel)ClassUtils.createNoArgConstructorClassInstance("org.opensha.sha.imt.attenRelImpl.BJF_1997_AttenRel");


createNoArgConstructorClassInstance

public static Object createNoArgConstructorClassInstance(ArrayList params,
                                                         ArrayList paramTypes,
                                                         String className)
Dynamically creates the class instance using the constructor with arguments. Note: Size the params ArrayList and paramTypes should be the same


getClassNameWithoutPackage

public static String getClassNameWithoutPackage(Class<?> theClass)