Rollingback r8521: Lazily generate LocaleInfoImpl (rebase from superdevmode) since htmlunit is failing.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@8524 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/i18n/client/LocaleInfo.java b/user/src/com/google/gwt/i18n/client/LocaleInfo.java
index 576e195..da0025a 100644
--- a/user/src/com/google/gwt/i18n/client/LocaleInfo.java
+++ b/user/src/com/google/gwt/i18n/client/LocaleInfo.java
@@ -33,7 +33,9 @@
* is a static. In the future, we would need a hash map from locale names
* to LocaleInfo instances.
*/
- private static LocaleInfo instance = new LocaleInfo();
+ private static LocaleInfo instance = new LocaleInfo(
+ (LocaleInfoImpl) GWT.create(LocaleInfoImpl.class),
+ (CldrImpl) GWT.create(CldrImpl.class));
/**
* @return an array of available locale names
@@ -50,7 +52,7 @@
* you might want to get the list of available locales in order to create
* instances of each of them.
*/
- return LocaleInfoImplHolder.infoImpl.getAvailableLocaleNames();
+ return instance.infoImpl.getAvailableLocaleNames();
}
/**
@@ -82,24 +84,20 @@
/*
* See the comment from getAvailableLocaleNames() above.
*/
- return LocaleInfoImplHolder.infoImpl.getLocaleNativeDisplayName(localeName);
+ return instance.infoImpl.getLocaleNativeDisplayName(localeName);
}
- private static class LocaleInfoImplHolder {
- static final LocaleInfoImpl infoImpl = GWT.create(LocaleInfoImpl.class);
- }
-
- private static class CldrImplHolder {
- static final CldrImpl cldrImpl = GWT.create(CldrImpl.class);
- }
-
/**
* @return true if any locale supported by this build of the app is RTL.
*/
public static boolean hasAnyRTL() {
- return LocaleInfoImplHolder.infoImpl.hasAnyRTL();
+ return instance.infoImpl.hasAnyRTL();
}
+ private final LocaleInfoImpl infoImpl;
+
+ private final CldrImpl cldrImpl;
+
private DateTimeConstants dateTimeConstants;
private DateTimeFormatInfo dateTimeFormatInfo;
@@ -111,6 +109,19 @@
* Any such subclass should override all methods.
*/
protected LocaleInfo() {
+ infoImpl = null;
+ cldrImpl = null;
+ }
+
+ /**
+ * Create a LocaleInfo instance, passing in the implementation classes.
+ *
+ * @param impl LocaleInfoImpl instance to use
+ * @param cldr CldrImpl instance to use
+ */
+ private LocaleInfo(LocaleInfoImpl impl, CldrImpl cldr) {
+ this.infoImpl = impl;
+ this.cldrImpl = cldr;
}
/**
@@ -133,7 +144,7 @@
* @return the name of this locale, such as "default, "en_US", etc
*/
public final String getLocaleName() {
- return LocaleInfoImplHolder.infoImpl.getLocaleName();
+ return infoImpl.getLocaleName();
}
/**
@@ -148,7 +159,7 @@
* @return true if this locale is right-to-left instead of left-to-right
*/
public final boolean isRTL() {
- return CldrImplHolder.cldrImpl.isRTL();
+ return cldrImpl.isRTL();
}
private void ensureDateTimeConstants() {
@@ -160,13 +171,13 @@
private void ensureDateTimeFormatInfo() {
if (dateTimeFormatInfo == null) {
- dateTimeFormatInfo = LocaleInfoImplHolder.infoImpl.getDateTimeFormatInfo();
+ dateTimeFormatInfo = infoImpl.getDateTimeFormatInfo();
}
}
private void ensureNumberConstants() {
if (numberConstants == null) {
- numberConstants = LocaleInfoImplHolder.infoImpl.getNumberConstants();
+ numberConstants = infoImpl.getNumberConstants();
}
}
}