dict.common
Class DictIndex

java.lang.Object
  extended by dict.common.DictIndex

public class DictIndex
extends java.lang.Object

Dictionary index. Read from file created by the index preparation program. See the description of the class dict.prepare.DictImport for the format of data files expected in this class. Since the reading of the data files is performed on JavaME, the files created during the preparation process are here threated as resources contained in the same Jar-File, where the JavaME frontend exists withid the BASEDIR directory.

Version:
$Revision: 21 $
Author:
Daniel Stoinski

Field Summary
static java.lang.String BASEDIR
          Base directory for the dictionary index files.
static java.lang.String INDEXFILE
          Name of the index description file.
private  java.lang.String[] m_dictfilename
          Names of dictionary files.
private  java.lang.Exception m_excp
          Exception occured while reading the index file.
private  boolean m_goon
          If the background thread has to be continued.
private  java.util.Hashtable m_index
          The index itself.
private  int m_type
          The type of the dictionary.
static int MAXENTRIES
          Maximal number of entries to show.
 
Constructor Summary
DictIndex()
          Initializes index for the index file INDEXFILE.
 
Method Summary
 void get(java.lang.String aKeyword, IResult aResHandler)
          Returns the descriptions for the given keyword.
 java.lang.Exception getExcp()
          Returns last excpetion occured.
 void getkeys(java.lang.String aKeyPattern, IResult aResHandler)
          Finds keys matching the given pattern.
 void init(IProgress aProgressHandler)
          Initializes the index from the file.
static java.lang.String mkpath(java.lang.String aKeyword)
          Creates a path specific for the given keyword.
 void stop()
          Stops any presently active operations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BASEDIR

public static final java.lang.String BASEDIR
Base directory for the dictionary index files.

See Also:
Constant Field Values

INDEXFILE

public static final java.lang.String INDEXFILE
Name of the index description file.

See Also:
Constant Field Values

MAXENTRIES

public static final int MAXENTRIES
Maximal number of entries to show.

See Also:
Constant Field Values

m_index

private java.util.Hashtable m_index
The index itself. Keys are index keywords, values are arrays of two integers: sequential number of the index keyword and the number of DictEntryRef entries.


m_dictfilename

private java.lang.String[] m_dictfilename
Names of dictionary files.


m_excp

private java.lang.Exception m_excp
Exception occured while reading the index file.


m_type

private int m_type
The type of the dictionary. One of the types defined in DictType.


m_goon

private boolean m_goon
If the background thread has to be continued. Set it to false in order to cancel the thread, regardless if initializing or searching.

Constructor Detail

DictIndex

public DictIndex()
Initializes index for the index file INDEXFILE. You must call init in order to load the index.

Method Detail

mkpath

public static java.lang.String mkpath(java.lang.String aKeyword)
Creates a path specific for the given keyword. Uses bits 8-10 hex of the hash kode of the keyword for the directory name and bits 0-7 hex as the file name.

Parameters:
aKeyword - the index keyword
Returns:
a path specific for the keyword or null on error

init

public void init(IProgress aProgressHandler)
Initializes the index from the file. Reads the index type and the dictionary resource names from the index resource INDEXFILE. Format of the index resource as described in the class dict.prepare.DictImport. See also class DictIndexLoadThread on how to start this method in a background thread - very necessary for JavaME.

Parameters:
aProgressHandler - progress handler for showing percentage of reading the index file.

getExcp

public java.lang.Exception getExcp()
Returns last excpetion occured.

Returns:
last exception occured or null, if no exceptions until now

stop

public void stop()
Stops any presently active operations.


get

public void get(java.lang.String aKeyword,
                IResult aResHandler)
Returns the descriptions for the given keyword. The method opens the index file suitable for this keyword (name according to mkpath()) and looks to the index keyword in there. If found, it retreives the array of dictionary entry references for the index keyword stored in the file and for each of them it uses DictEntryRef.readRelative() in order to extract the dictionary description for the keyword. Each retrieved dictionary description is returned using the callback aResHandler.addResult(). With the callback aResHandler.progress() the function informs about the present progress of the search process (the duration of this process may be siginificat on slower devices). Callback call to aResHandler.ready() informs the caller, that the process is ready. See also DictIndexSearchThread for on how to call this method in a background thread.

Parameters:
aKeyword - the keyword
aResHandler - handler for retrieving search results

getkeys

public void getkeys(java.lang.String aKeyPattern,
                    IResult aResHandler)
Finds keys matching the given pattern. Reads all keywords from the index configuration resource INDEXFILE and checks, if the given key pattern is a substring of keywords read from INDEXFILE. Each matching keyword (but no more than MAXENTRIES = 150) is returned to the caller using callback aResHandler.addResult(). The callback aResHandler.progress() informs the caller about the current progress of the searching process and a call aResHandler.ready() means, that the process has completed. See also the class DictIndexSKeysThread on how to call this method in a background thread.

Parameters:
aKeyPattern - a substring, which the key must contain
aResHandler - for retrieving search results.