- public class ObjectFactory {
- private static ResourceBundle rb;
- static{
- rb=ResourceBundle.getBundle("factory");
- }
- private static ObjectFactory instance=new ObjectFactory();
-
- private ObjectFactory(){}
-
- public static ObjectFactory getInstance(){
- return instance;
- }
- //根据配置文件返回不同的对象,当然调用的时候得传个配置文件中的key过来
- public <T>T getUserDaoImpl(String type){
- try {
- return (T) Class.forName(rb.getString(type)).newInstance();
- } catch (Exception e) {
- e.printStackTrace();
- throw new ExceptionInInitializerError(e);
- }
- }
- }
复制代码 |