Source code: com/eireneh/bible/book/BibleDriverManager.java
1
2 package com.eireneh.bible.book;
3
4 import java.io.*;
5 import java.util.*;
6 import java.net.*;
7
8 import com.eireneh.util.*;
9 import com.eireneh.bible.util.*;
10 import com.eireneh.bible.passage.*;
11
12 /**
13 * The BibleDriverManager is a set of helpers for things wanting to work
14 * with BibleDrivers and Bibles.
15 *
16 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
17 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
18 * Distribution Licence:<br />
19 * Project B is free software; you can redistribute it
20 * and/or modify it under the terms of the GNU General Public License,
21 * version 2 as published by the Free Software Foundation.<br />
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.<br />
26 * The License is available on the internet
27 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
28 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
30 * The copyright to this program is held by it's authors.
31 * </font></td></tr></table>
32 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
33 * @see docs.Licence
34 * @author Joe Walker
35 * @version D0.I0.T0
36 */
37 public class BibleDriverManager
38 {
39 /**
40 * Ensure that we can not be instansiated
41 */
42 private BibleDriverManager()
43 {
44 }
45
46 /**
47 * Add to the list of drivers
48 * @param driver The BookDriver to add
49 */
50 public static void registerDriver(BibleDriver driver)
51 {
52 drivers.addElement(driver);
53 }
54
55 /**
56 * Remove from the list of drivers
57 * @param driver The BookDriver to remove
58 */
59 public static void unregisterDriver(BibleDriver driver)
60 {
61 drivers.removeElement(driver);
62 }
63
64 /**
65 * Get an array of all the known drivers
66 * @return Found int or the default value
67 */
68 public static BibleDriver[] getDrivers()
69 {
70 BibleDriver[] da = new BibleDriver[drivers.size()];
71 for (int i=0; i<da.length; i++)
72 {
73 da[i] = (BibleDriver) drivers.elementAt(i);
74 }
75
76 return da;
77 }
78
79 /**
80 * Get the driver for a particular book name.
81 * @param name The Book name to find
82 * @return The BibleDriver that owns the book
83 */
84 public static BibleDriver getDriverForBible(String name) throws BookException
85 {
86 for (Enumeration en=drivers.elements(); en.hasMoreElements(); )
87 {
88 BibleDriver driver = (BibleDriver) en.nextElement();
89
90 if (driver.exists(name))
91 return driver;
92 }
93
94 throw new BookException("book_manager", new Object[] { name });
95 }
96
97 /** An array of BookDrivers */
98 private static Vector drivers = new Vector();
99
100 /**
101 * Initialize the driver array
102 */
103 static
104 {
105 // This is like Class.forName() however it compile time checked
106 Class for_name;
107
108 for_name = com.eireneh.bible.book.jdbc.JDBCBibleDriver.class;
109 for_name = com.eireneh.bible.book.ser.SerBibleDriver.class;
110 for_name = com.eireneh.bible.book.raw.RawBibleDriver.class;
111 }
112 }