package cn.itcast.notepad.dao;
import java.util.*;
import java.io.*;
import cn.itcast.notepad.utils.BookUtils;
public class DaoFactory {
public static UserDao getUserDao() {
try {
Class clazz = Class.forName(getClassName("user_dao"));
return (UserDao)clazz.newInstance();
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
public static StudentDao getStudentDao() {
try {
Class clazz = Class.forName(getClassName("student_dao"));
return (StudentDao)clazz.newInstance();
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
private static String getClassName(String key) {
Properties prop = new Properties();
try {
prop.load(BookUtils.getInputStream("config/book.properties"));
return prop.getProperty(key);
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
} |
|