View Javadoc
1   package ejava.examples.webtier.dao;
2   
3   import java.util.HashMap;
4   import java.util.Iterator;
5   
6   import org.apache.commons.logging.Log;
7   import org.apache.commons.logging.LogFactory;
8   
9   public class DAOFactory {
10      private static Log log = LogFactory.getLog(DAOFactory.class);
11      
12      private static HashMap<String, DAOTypeFactory> factories = 
13          new HashMap<String, DAOTypeFactory>();
14      
15      public static DAOTypeFactory getDAOTypeFactory() {
16          String name=null;
17          Iterator<String> itr = factories.keySet().iterator();
18          if (itr.hasNext()) {
19              name = factories.keySet().iterator().next();
20          }
21          log.debug("default DAO Factory name=" + name);
22          return (name==null) ? null : factories.get(name);
23      }
24      
25      public static DAOTypeFactory getDAOTypeFactory(String name) {
26          return (name==null) ? null : factories.get(name);
27      }
28      
29      public static void registerFactoryType(
30              String name, DAOTypeFactory typeFactory){
31          log.debug("registering DAOTypeFactory:" + name);
32          factories.put(name, typeFactory);
33      }
34  }