View Javadoc

1   /*
2    * $Id: ProcessControllerFactory.java,v 1.1 2004/12/15 14:18:10 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.core;
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 creating <code>ProcessControllerFactory</code>
19   * implementations.
20   * 
21   * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:10 $
22   * @author Patric Fornasier
23   * @author Pawel Kowalski
24   */
25  public class ProcessControllerFactory {
26  
27      private static Log log = LogFactory.getLog(ProcessControllerFactory.class);
28  
29      /***
30       * Creates a new <code>ProcessController</code>. The actual type is
31       * defined by the property <code>bexee.controller</code>.
32       * <p>
33       * If it is not set then {@link ProcessControllerImpl}will be created.
34       * 
35       * @return a <code>ProcessController</code> implementation
36       */
37      public static ProcessController createProcessController() {
38  
39          ProcessController controller = null;
40  
41          String className = BexeeProperties
42                  .getProperty(Constants.OPT_CONTROLLER);
43  
44          // if option is not set, create default factory
45          if (className == null) {
46              log.debug(Constants.OPT_DAO_FACTORY
47                      + " not set, creating default implementation: "
48                      + ProcessControllerImpl.class.getName());
49              controller = new ProcessControllerImpl();
50          } else {
51              try {
52                  // try to instantiate indicated class
53                  Class clazz = Class.forName(className);
54                  controller = (ProcessController) clazz.newInstance();
55              } catch (Exception e) {
56                  log.warn("unable to create " + className
57                          + ", creating default implementation: "
58                          + ProcessControllerImpl.class.getName());
59                  controller = new ProcessControllerImpl();
60              }
61          }
62  
63          return controller;
64      }
65  }