1 21 22 package org.opensubsystems.core.util; 23 24 import java.util.logging.Logger ; 25 26 import org.opensubsystems.core.error.OSSDynamicClassException; 27 import org.opensubsystems.core.error.OSSException; 28 29 37 public final class ClassUtils 38 { 39 41 44 private static Logger s_logger = Log.getInstance(ClassUtils.class); 45 46 48 51 private ClassUtils( 52 ) 53 { 54 } 56 57 59 67 public static Object createNewInstance( 68 String strClassName 69 ) throws OSSException 70 { 71 Object objInstance; 72 73 try 74 { 75 objInstance = createNewInstance(Class.forName(strClassName)); 76 } 77 catch (ClassNotFoundException eNoClass) 78 { 79 throw new OSSDynamicClassException("Unexpected exception.", eNoClass); 80 } 81 82 return objInstance; 83 } 84 85 93 public static Object createNewInstance( 94 Class templateClass 95 ) throws OSSException 96 { 97 Object objInstance; 98 99 try 100 { 101 objInstance = templateClass.newInstance(); 102 s_logger.finest("Instantiated class " + templateClass.getName()); 103 } 104 catch (IllegalAccessException eIllAcc) 105 { 106 throw new OSSDynamicClassException("Unexpected exception.", eIllAcc); 107 } 108 catch (InstantiationException ineExc) 109 { 110 throw new OSSDynamicClassException("Unexpected exception.", ineExc); 111 } 112 113 return objInstance; 114 } 115 } 116 | Popular Tags |