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

Quick Search    Search Deep

Source code: com/eireneh/bible/book/raw/InstsDisk.java


1   
2   package com.eireneh.bible.book.raw;
3   
4   import java.net.*;
5   import java.io.*;
6   
7   import com.eireneh.bible.passage.Verse;
8   import com.eireneh.bible.passage.Books;
9   
10  /**
11  * InstsDisk is a Base implementation of the Insts interface using the in
12  * on disk model (Disk). 
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 D0.I0.T0
34  */
35  public abstract class InstsDisk extends Disk implements Insts
36  {
37      /**
38      * Basic constructor
39      * @param raw Reference to the RawBible that is using us
40      * @param create Should we start all over again
41      */
42      public InstsDisk(RawBible raw, String leafname, boolean create) throws Exception
43      {
44          ctor(raw, leafname, create);
45      }
46  
47      /**
48      * Create a WordResource from a File that contains the dictionary.
49      * @param raw Reference to the RawBible that is using us
50      * @param create Should we start all over again
51      * @param messages We append stuff here if something went wrong
52      */
53      public InstsDisk(RawBible raw, String leafname, boolean create, StringBuffer messages)
54      {
55          try
56          {
57              ctor(raw, leafname, create);
58          }
59          catch (Exception ex)
60          {
61              messages.append(""+ex);
62          }
63      }
64  
65      /**
66      * This really should be a constructor, however the StringBuffer ctor
67      * wants to trap and muffle exceptions. and I can't do this:
68      * <code>try { this(...) } ...</code>
69      * @param raw Reference to the RawBible that is using us
70      * @param leafname The leaf name to read/write
71      * @param create Should we start all over again
72      */
73      private void ctor(RawBible raw, String leafname, boolean create) throws Exception
74      {
75          this.raw = raw;
76          this.leafname = leafname;
77          this.create = create;
78  
79          index = new long[Books.versesInBible()];
80  
81          if (create) save();
82          else        load();
83      }
84  
85      /**
86      * Load the Resource from a named file
87      */
88      public abstract void load() throws IOException, ClassNotFoundException, MalformedURLException;
89  
90      /**
91      * Lzay resources can not be used for creation
92      * @param out The stream to write to
93      */
94      public void save() throws IOException
95      {
96          throw new Error("You must use a WordInstsMem to write data");
97      }
98  
99      /**
100     * Retrieve an ordered list of the words in a Verse
101     * @param verse The Verse to retrieve words for
102     * @return An array of word indexes
103     */
104     public int[] getIndexes(Verse verse)
105     {
106         return getIndexes(verse.getOrdinal());
107     }
108 
109     /**
110     * Set a list of word indexes as the test to a Verse
111     * @param verse The Verse to set the words for
112     * @param indexes The array of word indexes
113     */
114     public void setIndexes(int[] indexes, Verse verse)
115     {
116         throw new Error("You must use a PuncInstsMem to write data");
117     }
118 
119     /** The file offsets */
120     protected long[] index;
121 
122     /** Are we allowed to create new indexes */
123     protected boolean create;
124 
125     /** The leafname of the file read */
126     protected String leafname;
127 
128     /** The RawBible co-ordinated the various classes that cache the files */
129     protected RawBible raw;
130 }