1   /**
2    * Distribution License:
3    * BibleDesktop is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU General Public License, version 2 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/gpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2005
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: SiteEditorFactory.java 2091 2011-03-07 04:15:31Z dmsmith $
21   */
22  package org.crosswire.bibledesktop.book.install;
23  
24  import java.util.Map;
25  import java.util.MissingResourceException;
26  
27  import org.crosswire.common.config.swing.FieldMap;
28  import org.crosswire.common.util.Logger;
29  import org.crosswire.common.util.PluginUtil;
30  import org.crosswire.jsword.book.install.Installer;
31  
32  /**
33   * Factory for SiteEditors.
34   * 
35   * @see gnu.gpl.License for license details.<br>
36   *      The copyright to this program is held by it's authors.
37   * @author DM Smith [dmsmith555 at yahoo dot com]
38   */
39  public final class SiteEditorFactory {
40      /**
41       * Prevent Use
42       */
43      private SiteEditorFactory() {
44      }
45  
46      /**
47       * Create a new SiteEditor
48       */
49      public static SiteEditor createSiteEditor(Installer installer) {
50          try {
51              Class<SiteEditor> clazz = map.get(installer.getType());
52              SiteEditor editor = null;
53              if (clazz != null) {
54                  editor = clazz.newInstance();
55                  editor.setInstaller(installer);
56              } else {
57                  log.warn("SiteEditor type (" + installer.getType() + ") unregistered.");
58              }
59              return editor;
60          } catch (MissingResourceException e) {
61              assert false : e;
62          } catch (InstantiationException e) {
63              assert false : e;
64          } catch (IllegalAccessException e) {
65              assert false : e;
66          }
67          return null;
68      }
69      /**
70       * The configuration table
71       */
72      private static Map<String, Class<SiteEditor>> map;
73  
74      /**
75       * Default map configuration
76       */
77      static {
78          map = PluginUtil.getImplementorsMap(SiteEditor.class);
79      }
80  
81      /**
82       * The log stream
83       */
84      private static final Logger log = Logger.getLogger(FieldMap.class);
85  }
86