ICU-1949 jikes compatibility, doc updates

X-SVN-Rev: 9084
This commit is contained in:
Doug Felt 2002-07-10 23:12:29 +00:00
parent 57b15cfd55
commit 0668a62e74
3 changed files with 70 additions and 27 deletions

View File

@ -27,37 +27,49 @@ public class ICULocaleService extends ICUService {
/**
* A subclass of Key that implements a locale fallback mechanism.
* The first locale to search for is the locale provided by the
* client, and the fallback locale to search for is the default
* client, and the fallback locale to search for is the current default
* locale. This is instantiated by ICULocaleService.</p>
*
* <p>Canonicalization adjusts the locale string so that the
* section before the first understore is in lower case, and the rest
* is in upper case, with no trailing underscores.
* is in upper case, with no trailing underscores.</p>
*/
public static class LocaleKey extends ICUService.Key {
private String primaryID;
private String fallbackID;
private String currentID;
/**
* Convenience method for createWithCanonical that canonicalizes both the
* primary and fallback IDs first.
*/
public static LocaleKey create(String primaryID, String fallbackID) {
String canonicalPrimaryID = LocaleUtility.canonicalLocaleString(primaryID);
String canonicalFallbackID = LocaleUtility.canonicalLocaleString(fallbackID);
return new LocaleKey(primaryID, canonicalPrimaryID, canonicalFallbackID);
}
/**
* Convenience method for createWithCanonical that canonicalizes the
* primary ID first, the fallback is assumed to already be canonical.
*/
public static LocaleKey createWithCanonicalFallback(String primaryID, String canonicalFallbackID) {
String canonicalPrimaryID = LocaleUtility.canonicalLocaleString(primaryID);
return new LocaleKey(primaryID, canonicalPrimaryID, canonicalFallbackID);
}
/**
* Create a LocaleKey with canonical primary and fallback IDs.
*/
public static LocaleKey createWithCanonical(String canonicalPrimaryID, String canonicalFallbackID) {
return new LocaleKey(canonicalPrimaryID, canonicalPrimaryID, canonicalFallbackID);
}
/**
* PrimaryID is the user's requested locale string in
* canonical form, fallbackID is the default locale's string
* in canonical form.
* PrimaryID is the user's requested locale string,
* canonicalPrimaryID is this string in canonical form,
* fallbackID is the current default locale's string in
* canonical form.
*/
protected LocaleKey(String primaryID, String canonicalPrimaryID, String canonicalFallbackID) {
super(primaryID);
@ -135,10 +147,17 @@ public class ICULocaleService extends ICUService {
private SoftReference cacheref;
private boolean included;
/**
* Convenience overload of MultipleKeyFactory(boolean) that defaults
* visible to true.
*/
public MultipleKeyFactory() {
this(true);
}
/**
* Constructs a MultipleKeyFactory whose ids are visible iff visible is true.
*/
public MultipleKeyFactory(boolean visible) {
this.visible = visible;
}
@ -327,7 +346,6 @@ public class ICULocaleService extends ICUService {
* inherited bundle);
*/
protected boolean acceptsLocale(Locale loc) {
try {
ResourceBundle bundle = ICULocaleData.loadResourceBundle(name, loc); // single resource bundle lookup
if (requiredContents != null) {
@ -339,9 +357,9 @@ public class ICULocaleService extends ICUService {
}
return true;
}
catch (Exception e) {
}
return false;
catch (Exception e) {
}
return false;
}
/**

View File

@ -23,7 +23,7 @@ import java.util.List;
* type and call the appropriate method on the listener.
*/
public abstract class ICUNotifier {
private Object notifyLock = new Object();
private final Object notifyLock = new Object();
private NotifyThread notifyThread;
private List listeners;
@ -43,12 +43,13 @@ public abstract class ICUNotifier {
synchronized (notifyLock) {
if (listeners == null) {
listeners = new ArrayList(5);
}
// identity equality check
Iterator iter = listeners.iterator();
while (iter.hasNext()) {
if (iter.next() == l) {
return;
} else {
// identity equality check
Iterator iter = listeners.iterator();
while (iter.hasNext()) {
if (iter.next() == l) {
return;
}
}
}
@ -95,7 +96,7 @@ public abstract class ICUNotifier {
synchronized (notifyLock) {
if (listeners != null) {
if (notifyThread == null) {
notifyThread = new NotifyThread();
notifyThread = new NotifyThread(this);
notifyThread.setDaemon(true);
notifyThread.start();
}
@ -108,8 +109,13 @@ public abstract class ICUNotifier {
/**
* The notification thread.
*/
private class NotifyThread extends Thread {
List queue = new LinkedList();
private static class NotifyThread extends Thread {
private final ICUNotifier notifier;
private final List queue = new LinkedList();
NotifyThread(ICUNotifier notifier) {
this.notifier = notifier;
}
/**
* Queue the notification on the thread.
@ -137,7 +143,7 @@ public abstract class ICUNotifier {
}
for (int i = 0; i < list.length; ++i) {
notifyListener((EventListener)list[i]);
notifier.notifyListener((EventListener)list[i]);
}
}
catch (InterruptedException e) {

View File

@ -54,7 +54,7 @@ import java.util.TreeMap;
* repeated effort.</p>
*
* <p>ICUService implements ICUNotifier, so that clients can register
* to to receive notification when factories are added or removed from
* to receive notification when factories are added or removed from
* the service. ICUService provides a default EventListener subinterface,
* ServiceListener, which can be registered with the service. When
* the service changes, the ServiceListener's serviceChanged method
@ -168,7 +168,7 @@ public class ICUService extends ICUNotifier {
* A default implementation of factory. This provides default
* implementations for subclasses, and implements a singleton
* factory that matches a single id and returns a single
* (possible deferred-initialized) instance. If visible is
* (possibly deferred-initialized) instance. If visible is
* true, updates the map passed to updateVisibleIDs with a
* mapping from id to itself.
*/
@ -177,19 +177,31 @@ public class ICUService extends ICUNotifier {
protected String id;
protected boolean visible;
/**
* Convenience constructor that calls SimpleFactory(Object, String, boolean)
* with visible true.
*/
public SimpleFactory(Object instance, String id) {
this(instance, id, true);
}
/**
* Construct a simple factory that maps a single id to a single
* service instance. If visible is true, the id will be visible.
* Neither the instance nor the id can be null.
*/
public SimpleFactory(Object instance, String id, boolean visible) {
if (instance == null || id == null) {
throw new IllegalArgumentException("instance and id must each not be null");
throw new IllegalArgumentException("Instance or id is null");
}
this.instance = instance;
this.id = id;
this.visible = visible;
}
/**
* Return the service instance if id equals the key's currentID.
*/
public Object create(Key key) {
if (id.equals(key.currentID())) {
return instance;
@ -197,10 +209,17 @@ public class ICUService extends ICUNotifier {
return null;
}
/**
* If visible, adds a mapping from id -> this to the result.
*/
public void updateVisibleIDs(Map result) {
if (visible) result.put(id, this);
}
/**
* If id equals this.id, returns id regardless of locale, otherwise
* returns null.
*/
public String getDisplayName(String id, Locale locale) {
return (visible && id.equals(this.id)) ? id : null;
}
@ -214,9 +233,10 @@ public class ICUService extends ICUNotifier {
}
/**
* <p>Given an id, return a service object, and the actual id under
* which it was found. If no service object matches this id,
* return null.</p>
* <p>Given an id, return a service object, and, if actualIDReturn
* is not null, the actual id under which it was found in the
* first element of actualIDReturn. If no service object matches
* this id, return null, and leave actualIDReturn unchanged.</p>
*
* <p>This tries each registered factory in order, and if none can
* generate a service object for the key, repeats the process with
@ -230,7 +250,6 @@ public class ICUService extends ICUNotifier {
if (factories.size() == 0) {
return null;
}
CacheEntry result = null;
Key key = createKey(id);