package foundation.server;
|
|
import java.lang.reflect.Method;
|
|
public class ObjectCreator {
|
|
|
@SuppressWarnings("unchecked")
|
public static <T> T create(String className) throws Exception {
|
T result = null;
|
|
Class<?> clazz = Class.forName(className);
|
|
Method getInstance = null;
|
try {
|
getInstance = clazz.getDeclaredMethod("getInstance");
|
}
|
catch (NoSuchMethodException e) {
|
}
|
|
if (getInstance != null) {
|
result = (T) getInstance.invoke(null);
|
}
|
else {
|
result = (T) clazz.newInstance();
|
}
|
|
return result;
|
}
|
|
}
|