package com.ithm.lotteryhm28.util;
import java.io.IOException;
import java.util.Properties;
import com.ithm.lotteryhm28.engine.UserEngine;
/**
* 工厂类
* @author Administrator
*
*/
public class BeanFactory {
private static Properties properties;
static{
properties=new Properties();
try {
properties.load(BeanFactory.class.getClassLoader().getResourceAsStream("bean.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 加载需要的实现类
* @param clazz
* @return
*/
public static<T> T getImpl(Class<T> clazz)
{
String key=clazz.getSimpleName();
String className = properties.getProperty(key);
try {
return (T) Class.forName(className).newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
UserEngine=com.sdingba.xxxx.su.impl.UserEngineImpl
UserEngine engine = BeanFactory.getImpl(UserEngine.class)