1   /**
2    * Distribution License:
3    * JSword is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU Lesser General Public License, version 2.1 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 Lesser General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/lgpl.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: SearcherFactory.java 2050 2010-12-09 15:31:45Z dmsmith $
21   */
22  package org.crosswire.jsword.index.search;
23  
24  import java.io.IOException;
25  
26  import org.crosswire.common.util.Logger;
27  import org.crosswire.common.util.PluginUtil;
28  import org.crosswire.jsword.book.Book;
29  import org.crosswire.jsword.book.BookException;
30  import org.crosswire.jsword.index.Index;
31  import org.crosswire.jsword.index.IndexManager;
32  import org.crosswire.jsword.index.IndexManagerFactory;
33  
34  /**
35   * Factory method for creating a new Searcher.
36   * 
37   * @see gnu.lgpl.License for license details.<br>
38   *      The copyright to this program is held by it's authors.
39   * @author Joe Walker [joe at eireneh dot com]
40   */
41  public final class SearcherFactory {
42      /**
43       * Prevent instantiation
44       */
45      private SearcherFactory() {
46      }
47  
48      /**
49       * Create a new Searcher.
50       */
51      public static Searcher createSearcher(Book book) throws InstantiationException {
52          try {
53              IndexManager imanager = IndexManagerFactory.getIndexManager();
54              Index index = imanager.getIndex(book);
55  
56              Searcher parser = PluginUtil.getImplementation(Searcher.class);
57              parser.init(index);
58  
59              return parser;
60          } catch (IOException e) {
61              log.error("createSearcher failed", e);
62              throw new InstantiationException();
63          } catch (BookException e) {
64              log.error("createSearcher failed", e);
65              throw new InstantiationException();
66          } catch (ClassCastException e) {
67              log.error("createSearcher failed", e);
68              throw new InstantiationException();
69          } catch (ClassNotFoundException e) {
70              log.error("createSearcher failed", e);
71              throw new InstantiationException();
72          } catch (IllegalAccessException e) {
73              log.error("createSearcher failed", e);
74              throw new InstantiationException();
75          }
76      }
77  
78      /**
79       * The log stream
80       */
81      private static final Logger log = Logger.getLogger(SearcherFactory.class);
82  }
83