forked from HelloWorld521/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeanFactory.java
More file actions
63 lines (56 loc) · 1.75 KB
/
BeanFactory.java
File metadata and controls
63 lines (56 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.briup.common;
import com.briup.dao.ICustomerDao;
import com.briup.dao.IOrderDao;
import com.briup.dao.impl.CustomerDaoImpl;
import com.briup.dao.impl.OrderDaoImpl;
import com.briup.service.ICustomerService;
import com.briup.service.IOrderService;
import com.briup.service.impl.CustomerServiceImpl;
import com.briup.service.impl.OrderServiceImpl;
public class BeanFactory {
private static ICustomerDao customerDao;
private static ICustomerService customerService;
private static IOrderDao orderDao;
private static IOrderService orderService;
public static final String CUSTOMERDAO = "customerDao";
public static final String CUSTOMERSERVICE = "customerService";
public static final String ORDERDAO = "orderDao";
public static final String ORDERSERVICE = "orderService";
public static Object getBean(String beanName){
if(beanName.equals(CUSTOMERDAO)){
return getCustomerDao();
}else if(beanName.equals(CUSTOMERSERVICE)){
return getCustomerService();
}else if(beanName.equals(ORDERDAO)){
return getOrderDao();
}else if(beanName.equals(ORDERSERVICE)){
return getOrderService();
}else{
return null;
}
}
private synchronized static ICustomerDao getCustomerDao(){
if(customerDao == null){
customerDao = new CustomerDaoImpl();
}
return customerDao;
}
private synchronized static ICustomerService getCustomerService(){
if(customerService == null){
customerService = new CustomerServiceImpl();
}
return customerService;
}
private synchronized static IOrderDao getOrderDao(){
if(orderDao == null){
orderDao = new OrderDaoImpl();
}
return orderDao;
}
private synchronized static IOrderService getOrderService(){
if(orderService == null){
orderService = new OrderServiceImpl();
}
return orderService;
}
}