public Object createObject ( String className , Class clazz ) throws ClassNotFoundException { Object object ; try { object = clazz . newInstance ( ) ; } catch ( InstantiationException ie ) { String info = "Could not create " + description + " object: " + className + ". Could not access object constructor: " ; info += ie . getMessage ( ) ; throw new ClassNotFoundException ( info , ie ) ; } catch ( IllegalAccessException iae ) { String info = "Could not create " + description + " object: " + className + ". Could not instantiate object. Does the object classname refer to an abstract class, " + "an interface or the like?: " ; info += iae . getMessage ( ) ; throw new ClassNotFoundException ( info , iae ) ; } catch ( ClassCastException cce ) { String info = "Could not create " + description + " object: " + className + ". The specified object classname does not refer to the proper type: " ; info += cce . getMessage ( ) ; throw new ClassNotFoundException ( info , cce ) ; } return object ; }
Dynamically creates an object