View Javadoc

1   /*
2    * $Id: DAOFactory.java,v 1.1 2004/12/15 14:18:09 patforna Exp $
3    *
4    * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
5    * Berne University of Applied Sciences
6    * School of Engineering and Information Technology
7    * All rights reserved.
8    */
9   package bexee.dao;
10  
11  import org.apache.commons.logging.Log;
12  import org.apache.commons.logging.LogFactory;
13  
14  import bexee.util.BexeeProperties;
15  import bexee.util.Constants;
16  
17  /***
18   * Abstract factory class for constructing various types of
19   * <code>DAOFactory</code> implementations, each factory supporting a
20   * different type of persistent storage implementation.
21   * <p>
22   * <code>DAOFactory</code> is an abstract class that is inherited and
23   * implemented by different concrete DAO factories to support storage
24   * implementation-specific access. The client can obtain a concrete DAO factory
25   * implementation such as <code>MemoryDAOFactory</code> and use it to obtain
26   * concrete DAOs that work with that specific storage implementation.
27   * 
28   * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:09 $
29   * @author Patric Fornasier
30   * @author Pawel Kowalski
31   */
32  public abstract class DAOFactory {
33  
34      private static Log log = LogFactory.getLog(DAOFactory.class);
35  
36      /***
37       * Creates a new <code>DAOFactory</code>. The actual type is defined by
38       * the property <code>bexee.dao.factory</code>.
39       * <p>
40       * If it is not set then {@link MemoryDAOFactory}will be created.
41       * 
42       * @return a <code>DAOFactory</code> implementation
43       */
44      public static DAOFactory getInstance() {
45  
46          DAOFactory factory = null;
47  
48          String className = BexeeProperties
49                  .getProperty(Constants.OPT_DAO_FACTORY);
50  
51          // if option is not set, create default factory
52          if (className == null) {
53              log.debug(Constants.OPT_DAO_FACTORY
54                      + " not set, creating default factory: "
55                      + MemoryDAOFactory.class.getName());
56              factory = new MemoryDAOFactory();
57          } else {
58              try {
59                  // try to instantiate indicated class
60                  Class clazz = Class.forName(className);
61                  factory = (DAOFactory) clazz.newInstance();
62              } catch (Exception e) {
63                  log.warn("unable to create " + className
64                          + ", creating default factory: "
65                          + MemoryDAOFactory.class.getName());
66                  factory = new MemoryDAOFactory();
67              }
68          }
69  
70          return factory;
71      }
72  
73      /***
74       * The concrete factories will have to implement this method.
75       * 
76       * @return a <code>BPELProcessDAO</code> implementation
77       */
78      public abstract BPELProcessDAO createBPELProcessDAO();
79  
80      /***
81       * The concrete factories will have to implement this method.
82       * 
83       * @return a <code>ProcessContextDAO</code> implementation
84       */
85      public abstract ProcessContextDAO createProcessContextDAO();
86  }