よく使用されるクラスインスタンス化
1733 ワード
/**
* <p> :</p>
* @author gao.tang
* @version 1.0
* @date 2011-3-7 02:12:31
*/
public class LoadExtClassUtil {
public static boolean isNull(String param){
return (param == null || "".equals(param));
}
public static Object getInstance(String extClass,String defaultExtClass){
Object object = null;
try {
object = Class.forName(extClass).newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
try {
object = Class.forName(defaultExtClass).newInstance();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
} catch (IllegalAccessException e) {
e.printStackTrace();
try {
object = Class.forName(defaultExtClass).newInstance();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
try {
object = Class.forName(defaultExtClass).newInstance();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
}
return object;
}
}