KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dao > ExampleDAOFactory


1 package test.dao;
2
3 /**
4  * Example of a DAO factory class. To see it in action, edit the CustomerBMPBean
5  * to use impl-factory="test.dao.ExampleDAOFactory" in its class-level ejb.dao
6  * tag instead of impl-jndi="dao".
7  */

8 public class ExampleDAOFactory {
9     
10     /* Prevent instance creation, since it's not needed */
11     private ExampleDAOFactory() {
12     }
13     
14     public static Object JavaDoc getDaoInstance(Class JavaDoc clazz) {
15         if (clazz == null) {
16             throw new IllegalArgumentException JavaDoc("No type supplied");
17         }
18         
19         // This example only handles the CustomerDAO. Additional cases could be
20
// added for other types, or a more sophisticated factory might use dynamic
21
// proxies.
22
if ("test.dao.CustomerDAO".equals(clazz.getName())) {
23             return new CustomerExampleDAO();
24         } else {
25             throw new IllegalArgumentException JavaDoc("Don't know how to create DAO of type " + clazz.getName());
26         }
27     }
28     
29 }
30
Popular Tags