ICU-2280 fix translit test breakage?

X-SVN-Rev: 11059
This commit is contained in:
Doug Felt 2003-02-15 00:29:04 +00:00
parent bb0daf402d
commit 61874c3596
2 changed files with 87 additions and 134 deletions

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/BreakIterator.java,v $
* $Date: 2003/01/28 18:55:41 $
* $Revision: 1.15 $
* $Date: 2003/02/15 00:29:03 $
* $Revision: 1.16 $
*
*****************************************************************************************
*/
@ -545,53 +545,6 @@ public abstract class BreakIterator implements Cloneable
return getBreakInstance(where, KIND_TITLE);
}
private static Class BI_FACTORY = null;
private static Method REGISTER_INSTANCE = null;
private static Method UNREGISTER = null;
private static Method CREATE_BREAK_INSTANCE = null;
private static Method GET_AVAILABLE_LOCALES = null;
private static final void setupService(){
try{
// load the class
BI_FACTORY = Class.forName("com.ibm.icu.text.BreakIteratorFactory");
// get the reference to registerInstance method
Class[] argTypes = { BreakIterator.class, Locale.class, int.class};
REGISTER_INSTANCE = BI_FACTORY.getDeclaredMethod("registerInstance",argTypes);
// get the reference to unregister method
argTypes = new Class[1];
argTypes[0] = Object.class;
UNREGISTER = BI_FACTORY.getDeclaredMethod("unregisterFactory",argTypes);
// get the reference to create instance method
argTypes = new Class[2];
argTypes[0] = Locale.class;
argTypes[1] = int.class;
CREATE_BREAK_INSTANCE = BI_FACTORY.getDeclaredMethod("createBreakInstance",argTypes);
// get the reference to getAvailableLocales
GET_AVAILABLE_LOCALES = BI_FACTORY.getDeclaredMethod("getAvailableLocales",null);
}catch(Exception e){
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
private static final Object invoke(Method method, Object[] args){
try{
return method.invoke(null,args);
}catch(Exception e){
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
/**
* Register a new break iterator of the indicated kind, to use in the given locale.
* Clones of the iterator will be returned
@ -604,21 +557,7 @@ public abstract class BreakIterator implements Cloneable
* @draft ICU 2.4
*/
public static Object registerInstance(BreakIterator iter, Locale locale, int kind) {
/* try {
Class[] argTypes = { BreakIterator.class, Locale.class, int.class };
Method regInstance = BI_FACTORY.getMethod("registerInstance",argTypes);
Object[] args = {iter,locale, new Integer(kind)};
return regInstance.invoke(null,args);
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}*/
Object[] args = {iter,locale, new Integer(kind)};
if(BI_FACTORY==null){
setupService();
}
return invoke(REGISTER_INSTANCE,args);
return getShim().registerInstance(iter, locale, kind);
}
/**
@ -629,27 +568,12 @@ public abstract class BreakIterator implements Cloneable
* @draft ICU 2.4
*/
public static boolean unregister(Object key) {
/*try {
Class[] argTypes = { Object.class };
Method unregister = BI_FACTORY.getMethod("unregister",argTypes);
Object[] args = {key};
Boolean retVal = (Boolean) unregister.invoke(null,args);
return retVal.booleanValue();
if (shim == null) {
return false;
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}*/
Object[] args = {key};
if(BI_FACTORY==null){
setupService();
}
return ((Boolean)invoke(UNREGISTER,args)).booleanValue();
return shim.unregister(key);
}
// end of registration
private static BreakIterator getBreakInstance(Locale where, int kind) {
@ -662,13 +586,10 @@ public abstract class BreakIterator implements Cloneable
}
}
}
Object[] args = new Object[]{where, new Integer(kind)};
if(BI_FACTORY==null){
setupService();
}
BreakIterator result = (BreakIterator)invoke(CREATE_BREAK_INSTANCE,
args);
// sigh, all to avoid linking in ICULocaleData...
BreakIterator result = getShim().createBreakIterator(where, kind);
BreakIteratorCache cache = new BreakIteratorCache(where, result);
iterCache[kind] = new SoftReference(cache);
return result;
@ -682,10 +603,8 @@ public abstract class BreakIterator implements Cloneable
*/
public static synchronized Locale[] getAvailableLocales()
{
if(BI_FACTORY==null){
setupService();
}
return (Locale[]) invoke(GET_AVAILABLE_LOCALES, null);
// to avoid linking ICULocaleData
return getShim().getAvailableLocales();
}
private static final class BreakIteratorCache {
@ -706,4 +625,31 @@ public abstract class BreakIterator implements Cloneable
return (BreakIterator) iter.clone();
}
}
static abstract class BreakIteratorServiceShim {
public abstract Object registerInstance(BreakIterator iter, Locale l, int k);
public abstract boolean unregister(Object key);
public abstract Locale[] getAvailableLocales();
public abstract BreakIterator createBreakIterator(Locale l, int k);
}
private static BreakIteratorServiceShim shim;
private static BreakIteratorServiceShim getShim() {
if (shim == null) {
try {
Class cls = Class.forName("com.ibm.icu.text.BreakIteratorFactory");
BreakIteratorServiceShim newshim = (BreakIteratorServiceShim)cls.newInstance();
synchronized(BreakIterator.class) {
if (shim == null) {
shim = newshim;
}
}
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
return shim;
}
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java,v $
* $Date: 2003/01/28 18:55:41 $
* $Revision: 1.1 $
* $Date: 2003/02/15 00:29:04 $
* $Revision: 1.2 $
*
*****************************************************************************************
*/
@ -28,7 +28,6 @@ import com.ibm.icu.impl.ICUService.Factory;
import com.ibm.icu.impl.ICUService.Key;
import com.ibm.icu.impl.LocaleUtility;
/**
* @author Ram
*
@ -37,9 +36,36 @@ import com.ibm.icu.impl.LocaleUtility;
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
class BreakIteratorFactory {
private static ICULocaleService service;
static ICULocaleService getService() {
final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim {
public Object registerInstance(BreakIterator iter, Locale locale, int kind) {
return getService().registerObject(iter, locale, kind);
}
public boolean unregister(Object key) {
if (service != null) {
return service.unregisterFactory((Factory)key);
}
return false;
}
public Locale[] getAvailableLocales() {
if (service == null) {
return ICULocaleData.getAvailableLocales();
} else {
return service.getAvailableLocales();
}
}
public BreakIterator createBreakIterator(Locale locale, int kind) {
if (service == null) {
return createBreakInstance(locale, kind);
}
return (BreakIterator)service.get(locale, kind);
}
private ICULocaleService service;
private ICULocaleService getService() {
if (service == null) {
ICULocaleService newService = new ICULocaleService("BreakIterator");
@ -50,7 +76,7 @@ class BreakIteratorFactory {
}
newService.registerFactory(new RBBreakIteratorFactory());
synchronized (BreakIterator.class) {
synchronized (this) {
if (service == null) {
service = newService;
}
@ -58,33 +84,24 @@ class BreakIteratorFactory {
}
return service;
}
static boolean unregisterFactory(Object key) {
if (service != null) {
return service.unregisterFactory((Factory)key);
}
return false;
}
static synchronized Locale[] getAvailableLocales()
{
if (service == null) {
return ICULocaleData.getAvailableLocales();
} else {
return service.getAvailableLocales();
}
private static final String[] KIND_NAMES = {
"Character", "Word", "Line", "Sentence", "Title"
};
private static BreakIterator createBreakInstance(Locale locale, int kind) {
String prefix = KIND_NAMES[kind];
return createBreakInstance(locale, kind,
prefix + "BreakRules",
prefix + "BreakDictionary");
}
static Object registerInstance(BreakIterator iter, Locale locale, int kind){
return getService().registerObject(iter, locale, kind);
}
static BreakIterator createBreakInstance(Locale where,
private static BreakIterator createBreakInstance(Locale where,
int kind,
String rulesName,
String dictionaryName) {
// System.out.println("rulesName: "+rulesName);
// System.out.println("dictionaryName: "+dictionaryName);
ResourceBundle bundle = ICULocaleData.getResourceBundle("BreakIteratorRules", where);
String[] classNames = bundle.getStringArray("BreakIteratorClasses");
@ -108,19 +125,9 @@ class BreakIteratorFactory {
}
return new RuleBasedBreakIterator(rules);
}
else
else {
throw new IllegalArgumentException("Invalid break iterator class \"" +
classNames[kind] + "\"");
}
private static final String[] KIND_NAMES = {
"Character", "Word", "Line", "Sentence", "Title"
};
static BreakIterator createBreakInstance(Locale locale, int kind) {
String prefix = KIND_NAMES[kind];
return createBreakInstance( locale, kind,
prefix + "BreakRules",
prefix + "BreakDictionary" );
}
}
}