net.sourceforge.wohenchan.convert
Class AbstractConverterTable

java.lang.Object
  |
  +--net.sourceforge.wohenchan.convert.AbstractConverterTable
All Implemented Interfaces:
ConverterTableInterface
Direct Known Subclasses:
CedictConverterTable, UnihanConverterTable

public abstract class AbstractConverterTable
extends java.lang.Object
implements ConverterTableInterface

This is an abstract base class for ConverterTableInterface. It contains convenience methods for firing events and initializing in a separate thread.

Version:
$Name: $ $Date: 2003/08/19 16:25:19 $
Author:
$Author: wtanaka $

Field Summary
private  java.util.Hashtable m_callersWaiting
          Map from Thread into Vector (a list of messages waiting to be delivered)
private  java.lang.Thread m_initThread
           
private  boolean m_isInitDone
           
private  ConverterListener m_passthroughListener
           
 
Constructor Summary
AbstractConverterTable()
           
 
Method Summary
static java.lang.String bytesToUnicode(byte[] input, java.lang.String encoding)
           
protected static void fireDone(ConverterListener listener)
           
protected static void fireEntryFound(ConverterListener listener, ConverterEntryInterface entry)
           
protected  void fireProgressChanged(ConverterListener listener, java.lang.String whatInProgress, int newProgress)
          Updates the progress for a given task
protected static void fireStatus(ConverterListener listener, java.lang.String newStatus)
           
protected static void fireTaskChange(ConverterListener listener, java.lang.String newTask)
           
protected abstract  void init(ConverterListener listener)
          Initialization method, to be overridden by subclasses.
 void initInOtherThread(ConverterListener listener)
          Calls the init method in a separate thread.
private  void joinJustInCase()
           
 void lookupByEnglishSubstring(java.lang.String str, ConverterListener listener)
          Locates ConverterEntryInterface objects corresponding to a given case insensitive English substring.
 void lookupByPinyin(java.lang.String pinyin, ConverterListener listener)
          Looks up a dictionary entry by pinyin.
 void lookupBySimplifiedChinese(java.lang.String chinese, ConverterListener listener)
          Looks up a converter table entry by simplified chinese characters.
 void lookupByTraditionalChinese(java.lang.String chinese, ConverterListener listener)
          Looks up a converter table entry by traditional chinese characters.
private  void passThroughConverterEvent(ConverterEvent evt)
          Notifies any waiting threads of a new event genrated by init.
private  void passThroughMessages(ConverterListener listener)
           
protected abstract  void postInitLookupByEnglishSubstring(java.lang.String str, ConverterListener listener)
          Locates ConverterEntryInterface objects corresponding to a given case insensitive English substring.
protected abstract  void postInitLookupByPinyin(java.lang.String pinyin, ConverterListener listener)
          Looks up a dictionary entry by pinyin.
protected abstract  void postInitLookupBySimplifiedChinese(java.lang.String chinese, ConverterListener listener)
          Looks up a converter table entry by simplified chinese.
protected abstract  void postInitLookupByTraditionalChinese(java.lang.String chinese, ConverterListener listener)
          Looks up a converter table entry by traditional chinese.
protected abstract  void postInitLookupByUnicode(java.lang.String unicode, ConverterListener listener)
          Looks up a ConverterEntry by Unicode character value.
private  void register()
           
static byte[] unicodeToBytes(java.lang.String input, java.lang.String encoding)
           
private  void waitForInit(ConverterListener listener)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_initThread

private java.lang.Thread m_initThread

m_isInitDone

private volatile boolean m_isInitDone

m_callersWaiting

private java.util.Hashtable m_callersWaiting
Map from Thread into Vector (a list of messages waiting to be delivered)


m_passthroughListener

private ConverterListener m_passthroughListener
Constructor Detail

AbstractConverterTable

public AbstractConverterTable()
Method Detail

initInOtherThread

public final void initInOtherThread(ConverterListener listener)
Calls the init method in a separate thread.


passThroughConverterEvent

private void passThroughConverterEvent(ConverterEvent evt)
Notifies any waiting threads of a new event genrated by init.


fireDone

protected static void fireDone(ConverterListener listener)

fireStatus

protected static void fireStatus(ConverterListener listener,
                                 java.lang.String newStatus)
                          throws AbortSearchException
AbortSearchException

fireTaskChange

protected static void fireTaskChange(ConverterListener listener,
                                     java.lang.String newTask)
                              throws AbortSearchException
AbortSearchException

fireEntryFound

protected static void fireEntryFound(ConverterListener listener,
                                     ConverterEntryInterface entry)
                              throws AbortSearchException
AbortSearchException

fireProgressChanged

protected void fireProgressChanged(ConverterListener listener,
                                   java.lang.String whatInProgress,
                                   int newProgress)
                            throws AbortSearchException
Updates the progress for a given task

Parameters:
whatInProgress - a string describing the thing in progress.
AbortSearchException

register

private void register()

passThroughMessages

private void passThroughMessages(ConverterListener listener)
                          throws AbortSearchException
AbortSearchException

joinJustInCase

private void joinJustInCase()

waitForInit

private void waitForInit(ConverterListener listener)
                  throws AbortSearchException
AbortSearchException

lookupByPinyin

public void lookupByPinyin(java.lang.String pinyin,
                           ConverterListener listener)
Description copied from interface: ConverterTableInterface
Looks up a dictionary entry by pinyin.

Specified by:
lookupByPinyin in interface ConverterTableInterface
Parameters:
pinyin - The input string is specified in pinyin. The string may be composed of the letters 'a'-'z' (lower case only), the numbers '1'-'5' and space (' '). The string is composed of at least 1 space-separated pinyin syllables. Syllables are separated with exactly one space. There is no leading or trailing space. Each syllable is composed of at least two letters followed by exactly one digit. The neutral tone is expicitly specified with '5'. u w/ umlaut (as in luu2 (donkey, palm tree), or luu3 (drizzle) is specified with uu.
listener - the ConverterListener to which this object should send its results

lookupBySimplifiedChinese

public void lookupBySimplifiedChinese(java.lang.String chinese,
                                      ConverterListener listener)
Description copied from interface: ConverterTableInterface
Looks up a converter table entry by simplified chinese characters.

Specified by:
lookupBySimplifiedChinese in interface ConverterTableInterface
Returns:
a non-null, possibly empty, array of results for this search.

lookupByTraditionalChinese

public void lookupByTraditionalChinese(java.lang.String chinese,
                                       ConverterListener listener)
Description copied from interface: ConverterTableInterface
Looks up a converter table entry by traditional chinese characters.

Specified by:
lookupByTraditionalChinese in interface ConverterTableInterface
Returns:
a non-null, possibly empty, array of results for this search.

lookupByEnglishSubstring

public void lookupByEnglishSubstring(java.lang.String str,
                                     ConverterListener listener)
Description copied from interface: ConverterTableInterface
Locates ConverterEntryInterface objects corresponding to a given case insensitive English substring.

Specified by:
lookupByEnglishSubstring in interface ConverterTableInterface
Returns:
a non-null, possibly empty, array of results for this search.

bytesToUnicode

public static java.lang.String bytesToUnicode(byte[] input,
                                              java.lang.String encoding)

unicodeToBytes

public static byte[] unicodeToBytes(java.lang.String input,
                                    java.lang.String encoding)

postInitLookupByPinyin

protected abstract void postInitLookupByPinyin(java.lang.String pinyin,
                                               ConverterListener listener)
Looks up a dictionary entry by pinyin. This won't be called until after the intialization is completed.

Parameters:
pinyin - The input string is specified in pinyin. The string may be composed of the letters 'a'-'z' (lower case only), the numbers '1'-'5' and space (' '). The string is composed of at least 1 space-separated pinyin syllables. Syllables are separated with exactly one space. There is no leading or trailing space. Each syllable is composed of at least two letters followed by exactly one digit. The neutral tone is expicitly specified with '5'. u w/ umlaut (as in luu2 (donkey, palm tree), or luu3 (drizzle) is specified with uu.
Returns:
a non-null, possibly empty, array of results for this search.

postInitLookupBySimplifiedChinese

protected abstract void postInitLookupBySimplifiedChinese(java.lang.String chinese,
                                                          ConverterListener listener)
Looks up a converter table entry by simplified chinese. This won't be called until after the initialization is completed.

Returns:
a non-null, possibly empty, array of results for this search.

postInitLookupByTraditionalChinese

protected abstract void postInitLookupByTraditionalChinese(java.lang.String chinese,
                                                           ConverterListener listener)
Looks up a converter table entry by traditional chinese. This won't be called until after the initialization is completed.

Returns:
a non-null, possibly empty, array of results for this search.

postInitLookupByUnicode

protected abstract void postInitLookupByUnicode(java.lang.String unicode,
                                                ConverterListener listener)
Looks up a ConverterEntry by Unicode character value. This won't be called until after the initialization is completed.

Returns:
a non-null, possibly empty, array of results for this search.

postInitLookupByEnglishSubstring

protected abstract void postInitLookupByEnglishSubstring(java.lang.String str,
                                                         ConverterListener listener)
Locates ConverterEntryInterface objects corresponding to a given case insensitive English substring. This won't be called until after the initialization is completed.

Returns:
a non-null, possibly empty, array of results for this search.

init

protected abstract void init(ConverterListener listener)
                      throws java.io.IOException
Initialization method, to be overridden by subclasses.

java.io.IOException