Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/eireneh/bible/passage/PassageFactory.java


1   
2   package com.eireneh.bible.passage;
3   
4   import com.eireneh.util.LogicError;
5   
6   /**
7    * A PassageFactory is in charge of creating Passages. The point of
8    * implementing it as a Factory is that the Passage interface may be
9    * implemented in different ways eached optimized for a different
10   * task. The user should not need to know which implementation is best
11   * at each task, so it asks a PassageFactory, to create what it thinks
12   * best.
13   *
14   * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
15   * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
16   * Distribution Licence:<br />
17   * Project B is free software; you can redistribute it
18   * and/or modify it under the terms of the GNU General Public License,
19   * version 2 as published by the Free Software Foundation.<br />
20   * This program is distributed in the hope that it will be useful,
21   * but WITHOUT ANY WARRANTY; without even the implied warranty of
22   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23   * General Public License for more details.<br />
24   * The License is available on the internet
25   * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
26   * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27   * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
28   * The copyright to this program is held by it's authors.
29   * </font></td></tr></table>
30   * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
31   * @see docs.Licence
32   * @author Joe Walker
33   * @version $Id:$
34   * @stereotype factory
35   */
36  public class PassageFactory
37  {
38      /** Optimize the Passage for speed */
39      public static final int SPEED = 0;
40  
41      /** Optimize the Passage for speed */
42      public static final int WRITE_SPEED = 1;
43  
44      /** Optimize the Passage for size */
45      public static final int SIZE = 2;
46  
47      /** Optimize the Passage for a mix */
48      public static final int MIX = 3;
49  
50      /** Optimize the Passage for tally operations */
51      public static final int TALLY = 4;
52  
53      /**
54       * Set the default reference type. Must be one of:<ul>
55       * <li>PassageFactory.SPEED
56       * <li>PassageFactory.WRITE_SPEED
57       * <li>PassageFactory.SIZE
58       * <li>PassageFactory.MIX
59       * <li>PassageFactory.TALLY
60       * </ul>
61       * @param default_type The new default type.
62       */
63      public static void setDefaultPassage(int default_type)
64      {
65          PassageFactory.default_type = default_type;
66      }
67  
68      /**
69       * Create an empty Passage using the default type.
70       * @return The new Passage
71       */
72      public static Passage createPassage()
73      {
74          return createPassage(default_type);
75      }
76  
77      /**
78       * Create an empty Passage using the default type. And set the
79       * contents of the Passage using a string.
80       * @param name The Passage description.
81       * @return The new Passage
82       */
83      public static Passage createPassage(String name) throws NoSuchVerseException
84      {
85          return createPassage(default_type, name);
86      }
87  
88      /**
89       * Create an empty Passage using a specified type.
90       * @param type The type of Passage to create.
91       * @return The new Passage
92       * @see #setDefaultPassage(int)
93       */
94      public static Passage createPassage(int type)
95      {
96          switch (type)
97          {
98          case MIX:
99              return new RangedPassage();
100 
101         case WRITE_SPEED:
102             return new BitwisePassage();
103 
104         case SPEED:
105             return new RocketPassage();
106 
107         case SIZE:
108             return new DistinctPassage();
109 
110         case TALLY:
111             return new PassageTally();
112 
113         default:
114             throw new IllegalArgumentException(""+type);
115         }
116     }
117 
118     /**
119      * Create an empty Passage using a specified type. And set the
120      * contents of the Passage using a string.
121      * @param type The type of Passage to create.
122      * @param name The Passage description.
123      * @return The new Passage
124      * @see #setDefaultPassage(int)
125      */
126     public static Passage createPassage(int type, String name) throws NoSuchVerseException
127     {
128         switch (type)
129         {
130         case MIX:
131             return new RangedPassage(name);
132 
133         case WRITE_SPEED:
134             return new BitwisePassage(name);
135 
136         case SPEED:
137             return new RocketPassage(name);
138 
139         case SIZE:
140             return new DistinctPassage(name);
141 
142         case TALLY:
143             return new PassageTally(name);
144 
145         default:
146             throw new IllegalArgumentException(""+type);
147         }
148     }
149 
150     /**
151      * Create a Passage with all bits of the Bible set.
152      * @return The new Passage
153      */
154     public static Passage getWholeBiblePassage()
155     {
156         try
157         {
158             if (whole == null)
159                 whole = new ReadOnlyPassage(PassageFactory.createPassage("Gen 1:1-Rev 22:21"), true);
160 
161             return whole;
162         }
163         catch (Exception ex)
164         {
165             throw new LogicError(ex);
166         }
167     }
168 
169     /** The cached whole Bible passage */
170     private static Passage whole;
171 
172     /** The default type */
173     private static int default_type = SPEED;
174 
175     /**
176      * @link dependency
177      */
178     /*#Passage lnkPassage;*/
179 }