You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/06/13 10:57:22 UTC

svn commit: r1492576 - in /sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis: internal/util/Supervisor.java setup/About.java

Author: desruisseaux
Date: Thu Jun 13 08:57:22 2013
New Revision: 1492576

URL: http://svn.apache.org/r1492576
Log:
More consistent contract for the 'About.configuration(...)' methods.

Modified:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Supervisor.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/setup/About.java

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Supervisor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Supervisor.java?rev=1492576&r1=1492575&r2=1492576&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Supervisor.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Supervisor.java [UTF-8] Thu Jun 13 08:57:22 2013
@@ -16,8 +16,10 @@
  */
 package org.apache.sis.internal.util;
 
+import java.util.EnumSet;
 import java.util.List;
 import java.util.Locale;
+import java.util.TimeZone;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 import javax.management.ObjectName;
@@ -34,7 +36,6 @@ import java.lang.management.ManagementFa
 
 import org.apache.sis.setup.About;
 import org.apache.sis.util.Localized;
-import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.collection.TreeTable;
@@ -79,7 +80,7 @@ public final class Supervisor extends St
             final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
             try {
                 final ObjectName n = new ObjectName("org.apache.sis:type=Supervisor");
-                server.registerMBean(new Supervisor(Locale.getDefault()), n);
+                server.registerMBean(new Supervisor(null, null), n);
                 name = n; // Store only on success.
             } catch (SecurityException | JMException e) {
                 Logging.unexpectedException(Logger.getLogger("org.apache.sis"), Supervisor.class, "register", e);
@@ -105,24 +106,30 @@ public final class Supervisor extends St
     }
 
     /**
-     * The locale for producing the messages.
+     * The locale for producing the messages, or {@code null} for the default.
      */
     private final Locale locale;
 
     /**
+     * The timezone for formatting the dates, or {@code null} for the default.
+     */
+    private final TimeZone timezone;
+
+    /**
      * Creates a new {@code Supervisor} which will report messages in the given locale.
      *
-     * @param  locale The locale to use for reporting messages.
+     * @param  locale The locale to use for reporting messages, or {@code null} for the default.
+     * @param  timezone The timezone for formatting the dates, or {@code null} for the default.
      * @throws NotCompliantMBeanException Should never happen.
      */
-    public Supervisor(final Locale locale) throws NotCompliantMBeanException {
+    public Supervisor(final Locale locale, final TimeZone timezone) throws NotCompliantMBeanException {
         super(SupervisorMBean.class);
-        ArgumentChecks.ensureNonNull("locale", locale);
-        this.locale = locale;
+        this.locale   = locale;
+        this.timezone = timezone;
     }
 
     /**
-     * Returns the supervisor locale.
+     * Returns the supervisor locale, or {@code null} for the default locale.
      */
     @Override
     public Locale getLocale() {
@@ -182,7 +189,8 @@ public final class Supervisor extends St
      */
     private String getDescription(final String resourceKey) {
         return ResourceBundle.getBundle("org.apache.sis.internal.util.Descriptions",
-                locale, Supervisor.class.getClassLoader()).getString(resourceKey);
+                (locale != null) ? locale : Locale.getDefault(Locale.Category.DISPLAY),
+                Supervisor.class.getClassLoader()).getString(resourceKey);
     }
 
     // -----------------------------------------------------------------------
@@ -194,7 +202,7 @@ public final class Supervisor extends St
      */
     @Override
     public TreeTable configuration() {
-        return About.configuration(locale);
+        return About.configuration(EnumSet.allOf(About.class), locale, timezone);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/setup/About.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/setup/About.java?rev=1492576&r1=1492575&r2=1492576&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/setup/About.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/setup/About.java [UTF-8] Thu Jun 13 08:57:22 2013
@@ -134,25 +134,37 @@ public enum About {
 
     /**
      * Returns all known information about the current Apache SIS running environment.
+     * The information are formatted using the system default locale and timezone.
+     *
+     * <p>This convenience method is equivalent to the following code:</p>
+     *
+     * {@preformat java
+     *     return configuration(EnumSet.allOf(About.class), null, null);
+     * }
      *
-     * @param  locale The locale to use for formatting the texts in the tree.
      * @return Configuration information, as a tree for grouping some configuration by sections.
      */
-    public static TreeTable configuration(final Locale locale) {
-        return configuration(EnumSet.allOf(About.class), locale, null);
+    public static TreeTable configuration() {
+        return configuration(EnumSet.allOf(About.class), null, null);
     }
 
     /**
      * Returns a subset of the information about the current Apache SIS running environment.
      *
      * @param  sections The section for which information are desired.
-     * @param  locale   The locale to use for formatting the texts in the tree.
+     * @param  locale   The locale to use for formatting the texts in the tree, or {@code null} for the default.
      * @param  timezone The timezone to use for formatting the dates, or {@code null} for the default.
      * @return Configuration information, as a tree for grouping some configuration by sections.
      */
-    public static TreeTable configuration(final Set<About> sections, final Locale locale, final TimeZone timezone) {
+    public static TreeTable configuration(final Set<About> sections, Locale locale, final TimeZone timezone) {
         ArgumentChecks.ensureNonNull("sections", sections);
-        ArgumentChecks.ensureNonNull("locale", locale);
+        final Locale formatLocale;
+        if (locale != null) {
+            formatLocale = locale;
+        } else {
+            locale       = Locale.getDefault(Locale.Category.DISPLAY);
+            formatLocale = Locale.getDefault(Locale.Category.FORMAT);
+        }
         String userHome = null;
         String javaHome = null;
         final Date now = new Date();
@@ -218,7 +230,7 @@ fill:   for (int i=0; ; i++) {
                             nameKey = Vocabulary.Keys.Timezone;
                             final boolean inDaylightTime = current.inDaylightTime(now);
                             value = concatenate(current.getDisplayName(inDaylightTime, TimeZone.LONG, locale), current.getID(), true);
-                            final DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
+                            final DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT, formatLocale);
                             df.setTimeZone(TimeZone.getTimeZone("UTC"));
                             int offset = current.getOffset(now.getTime());
                             StringBuffer buffer = format(df, offset, new StringBuffer("UTC "));
@@ -235,7 +247,7 @@ fill:   for (int i=0; ; i++) {
                 case 5: {
                     if (sections.contains(LOCALIZATION)) {
                         nameKey = Vocabulary.Keys.CurrentDateTime;
-                        final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
+                        final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, formatLocale);
                         if (timezone != null) {
                             df.setTimeZone(timezone);
                         }