📄 daofactory.java
字号:
/*
* DaoFactory.java
*
* Created on 2006年9月23日, 下午5:46
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.shopping.dao;
import java.io.*;
/**
*
* @author 曹昊
*/
public class DaoFactory
{
/* public static ShoppingCartDao getInstance(String name)
{
if (name.equals("JDBC"))
{
return new JdbcDaoImpl();
} else if (name.equals("HIBR"))
{
return new HibrDaoImpl();
} else
return null;
}*/
public static ShoppingCartDao getInstance()
{
Object o = null;
try
{
//读配置文件
ClassLoader loader = DaoFactory.class.getClassLoader();
InputStream input = loader.getResourceAsStream("com/shopping/resource/impl.properties");
InputStreamReader isr = new InputStreamReader(input);
BufferedReader in = new BufferedReader(isr);
String name = in.readLine();
in.close();
Class c = Class.forName("com.shopping.dao." + name + "DaoImpl");
o = c.newInstance();
} catch (FileNotFoundException ex)
{
ex.printStackTrace();
} catch (InstantiationException ex)
{
ex.printStackTrace();
} catch (IllegalAccessException ex)
{
ex.printStackTrace();
} catch (ClassNotFoundException ex)
{
ex.printStackTrace();
} catch (IOException ex)
{
ex.printStackTrace();
}
return (ShoppingCartDao) o;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -