Added support for using LocaleInfo even if the I18N module isn't included.
isRTL() always returns false, and any methods returning objects will return
null if I18N isn't imported.

Patch by: jat
Review by: jgw



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1802 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/i18n/client/impl/LocaleInfoImpl.java b/user/src/com/google/gwt/i18n/client/impl/LocaleInfoImpl.java
index 6520bdd..d391e7c 100644
--- a/user/src/com/google/gwt/i18n/client/impl/LocaleInfoImpl.java
+++ b/user/src/com/google/gwt/i18n/client/impl/LocaleInfoImpl.java
@@ -19,19 +19,24 @@
  * Implementation detail of LocaleInfo -- not a public API and subject to
  * change.
  * 
- * Generated interface for locale information.
+ * Generated interface for locale information.  The default implementation
+ * returns null, which is used if the i18n module is not imported.
  * 
  * @see com.google.gwt.i18n.client.LocaleInfo
  */
-public interface LocaleInfoImpl {
+public class LocaleInfoImpl {
 
   /**
    * @return an array of available locale names
    */
-  String[] getAvailableLocaleNames();
+  public String[] getAvailableLocaleNames() {
+    return null;
+  }
 
   /**
    * @return the current locale name, such as "default, "en_US", etc.
    */
-  String getLocaleName();
+  public String getLocaleName() {
+    return null;
+  }
 }
diff --git a/user/src/com/google/gwt/i18n/rebind/LocaleInfoGenerator.java b/user/src/com/google/gwt/i18n/rebind/LocaleInfoGenerator.java
index 7791659..9542fc4 100644
--- a/user/src/com/google/gwt/i18n/rebind/LocaleInfoGenerator.java
+++ b/user/src/com/google/gwt/i18n/rebind/LocaleInfoGenerator.java
@@ -56,12 +56,14 @@
     TypeOracle typeOracle = context.getTypeOracle();
     // Get the current locale and interface type.
     PropertyOracle propertyOracle = context.getPropertyOracle();
-    String locale;
+    String locale = null;
+    String[] localeValues = null;
     try {
       locale = propertyOracle.getPropertyValue(logger, PROP_LOCALE);
+      localeValues = propertyOracle.getPropertyValueSet(logger, PROP_LOCALE);
     } catch (BadPropertyValueException e) {
-      logger.log(TreeLogger.ERROR, "Could not parse specified locale", e);
-      throw new UnableToCompleteException();
+      logger.log(TreeLogger.TRACE, "LocaleInfo used without I18N module, using defaults", e);
+      return LocaleInfoImpl.class.getName();
     }
 
     JClassType targetClass;
@@ -83,27 +85,18 @@
     if (pw != null) {
       ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(
           packageName, className);
-      factory.addImplementedInterface(targetClass.getQualifiedSourceName());
+      factory.setSuperclass(targetClass.getQualifiedSourceName());
       SourceWriter writer = factory.createSourceWriter(context, pw);
-      writer.println("private static final String[] availableLocales = new String[] {");
-      try {
-        for (String propval : propertyOracle.getPropertyValueSet(logger,
-            PROP_LOCALE)) {
-          writer.println("  \"" + propval.replaceAll("\"", "\\\"") + "\",");
-        }
-      } catch (BadPropertyValueException e) {
-        logger.log(TreeLogger.ERROR,
-            "No locale property defined -- did you inherit the I18N module?", e);
-        throw new UnableToCompleteException();
-      }
-      writer.println("};");
-      writer.println();
       writer.println("public String getLocaleName() {");
       writer.println("  return \"" + locale + "\";");
       writer.println("}");
       writer.println();
       writer.println("public String[] getAvailableLocaleNames() {");
-      writer.println("  return availableLocales;");
+      writer.println("  return new String[] {");
+      for (String propval : localeValues) {
+        writer.println("    \"" + propval.replaceAll("\"", "\\\"") + "\",");
+      }
+      writer.println("  };");
       writer.println("}");
       writer.commit(logger);
     }
diff --git a/user/test/com/google/gwt/i18n/I18NTest_none.gwt.xml b/user/test/com/google/gwt/i18n/I18NTest_none.gwt.xml
new file mode 100644
index 0000000..4ccde67
--- /dev/null
+++ b/user/test/com/google/gwt/i18n/I18NTest_none.gwt.xml
@@ -0,0 +1,20 @@
+<!--                                                                        -->
+<!-- Copyright 2008 Google Inc.                                             -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License"); you    -->
+<!-- may not use this file except in compliance with the License. You may   -->
+<!-- may obtain a copy of the License at                                    -->
+<!--                                                                        -->
+<!-- http://www.apache.org/licenses/LICENSE-2.0                             -->
+<!--                                                                        -->
+<!-- Unless required by applicable law or agreed to in writing, software    -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS,      -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        -->
+<!-- implied. License for the specific language governing permissions and   -->
+<!-- limitations under the License.                                         -->
+
+<module>
+	<!-- Inherit the JUnit support -->
+	<inherits name='com.google.gwt.junit.JUnit'/>
+	<!-- Include client-side source for the test cases -->
+	<source path="client"/>
+</module>
diff --git a/user/test/com/google/gwt/i18n/client/LocaleInfo_none_Test.java b/user/test/com/google/gwt/i18n/client/LocaleInfo_none_Test.java
new file mode 100644
index 0000000..e505f28
--- /dev/null
+++ b/user/test/com/google/gwt/i18n/client/LocaleInfo_none_Test.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2008 Google Inc.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.i18n.client;
+
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Test that LocaleInfo works properly if i18n isn't imported.
+ */
+public class LocaleInfo_none_Test extends GWTTestCase {
+
+  public String getModuleName() {
+    return "com.google.gwt.i18n.I18NTest_none";
+  }
+
+  public void testLocaleInfo() {
+    LocaleInfo localeInfo = LocaleInfo.getCurrentLocale();
+    assertFalse(localeInfo.isRTL());
+    assertNull(localeInfo.getLocaleName());
+    assertNull(LocaleInfo.getAvailableLocaleNames());
+  }
+}