sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1420813 - in /sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis: internal/jaxb/gmd/CodeListProxy.java util/iso/CodeLists.java util/iso/ResourceInternationalString.java util/iso/Types.java
Date Wed, 12 Dec 2012 16:32:55 GMT
Author: desruisseaux
Date: Wed Dec 12 16:32:53 2012
New Revision: 1420813

URL: http://svn.apache.org/viewvc?rev=1420813&view=rev
Log:
Nail down the class loader to use for fetching resources.

Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/CodeLists.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/ResourceInternationalString.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java?rev=1420813&r1=1420812&r2=1420813&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
Wed Dec 12 16:32:53 2012
@@ -180,7 +180,8 @@ public final class CodeListProxy {
         if (locale != null) {
             final String key = classID + '.' + fieldID;
             try {
-                value = ResourceBundle.getBundle("org.opengis.metadata.CodeLists", locale).getString(key);
+                value = ResourceBundle.getBundle("org.opengis.metadata.CodeLists",
+                        locale, CodeList.class.getClassLoader()).getString(key);
             } catch (MissingResourceException e) {
                 Logging.recoverableException(CodeListAdapter.class, "marshal", e);
             }

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/CodeLists.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/CodeLists.java?rev=1420813&r1=1420812&r2=1420813&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/CodeLists.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/CodeLists.java Wed
Dec 12 16:32:53 2012
@@ -175,7 +175,7 @@ public final class CodeLists extends Sta
          */
         final String key = getListName(code) + '.' + getCodeName(code);
         try {
-            return ResourceBundle.getBundle("org.opengis.metadata.CodeLists", locale).getString(key);
+            return ResourceBundle.getBundle("org.opengis.metadata.CodeLists", locale, Types.CLASSLOADER).getString(key);
         } catch (MissingResourceException e) {
             Logging.recoverableException(CodeLists.class, "getCodeTitle", e);
             return getCodeTitle(code);
@@ -207,19 +207,8 @@ public final class CodeLists extends Sta
      * @see #getCodeTitle(CodeList, Locale)
      * @see Types#getDescription(Class, Locale)
      */
-    public static String getDescription(final CodeList<?> code, Locale locale) {
-        if (code != null) {
-            if (locale == null) {
-                locale = Locale.getDefault();
-            }
-            final String key = getListName(code) + '.' + getCodeName(code);
-            try {
-                return ResourceBundle.getBundle("org.opengis.metadata.Descriptions", locale).getString(key);
-            } catch (MissingResourceException e) {
-                Logging.recoverableException(CodeLists.class, "getDescription", e);
-            }
-        }
-        return null;
+    public static String getDescription(final CodeList<?> code, final Locale locale)
{
+        return (code != null) ? Types.getDescription(getListName(code) + '.' + getCodeName(code),
locale) : null;
     }
 
     /**

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/ResourceInternationalString.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/ResourceInternationalString.java?rev=1420813&r1=1420812&r2=1420813&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/ResourceInternationalString.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/ResourceInternationalString.java
Wed Dec 12 16:32:53 2012
@@ -38,7 +38,7 @@ import java.util.Objects;
  * resource bundle is loaded at runtime for the client's language by looking for a class
or a
  * properties file with the right suffix, for example {@code "_en"} for English or {@code
"_fr"}
  * for French. This mechanism is explained in J2SE javadoc for the
- * {@link ResourceBundle#getBundle(String,Locale,ClassLoader) getBundle} static method.
+ * {@link ResourceBundle#getBundle(String, Locale, ClassLoader) getBundle(…)} static
method.
  *
  * {@section Example}
  * If a file named "{@code MyResources.properties}" exists in the package {@code org.mypackage}
@@ -91,16 +91,6 @@ public class ResourceInternationalString
     private final transient ClassLoader loader;
 
     /**
-     * Creates a new international string from the specified resource bundle and key.
-     *
-     * @param resources The name of the resource bundle, as a fully qualified class name.
-     * @param key The key for the resource to fetch.
-     */
-    public ResourceInternationalString(final String resources, final String key) {
-        this(resources, key, null);
-    }
-
-    /**
      * Creates a new international string from the specified resource bundle, key and class
loader.
      *
      * @param resources The name of the resource bundle, as a fully qualified class name.
@@ -125,7 +115,7 @@ public class ResourceInternationalString
      * @param  locale The locale for which to get the resource bundle.
      * @return The resource bundle for the given locale.
      *
-     * @see ResourceBundle#getBundle(String,Locale)
+     * @see ResourceBundle#getBundle(String, Locale)
      */
     protected ResourceBundle getBundle(final Locale locale) {
         return (loader == null) ? ResourceBundle.getBundle(resources, locale) :

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java?rev=1420813&r1=1420812&r2=1420813&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java Wed Dec
12 16:32:53 2012
@@ -55,6 +55,11 @@ import org.apache.sis.internal.util.Defa
  */
 public final class Types extends Static {
     /**
+     * The class loader to use for fetching GeoAPI resources.
+     */
+    static final ClassLoader CLASSLOADER = UML.class.getClassLoader();
+
+    /**
      * The types for ISO 19115 UML identifiers. The keys are UML identifiers. Values
      * are either class names as {@link String} objects, or the {@link Class} instances.
      *
@@ -166,18 +171,26 @@ public final class Types extends Static 
      *
      * @see CodeLists#getDescription(CodeList, Locale)
      */
-    public static String getDescription(final Class<?> type, Locale locale) {
-        if (type != null) {
-            final String name = getStandardName(type);
-            if (name != null) {
-                if (locale == null) {
-                    locale = Locale.getDefault();
-                }
-                try {
-                    return ResourceBundle.getBundle("org.opengis.metadata.Descriptions",
locale).getString(name);
-                } catch (MissingResourceException e) {
-                    Logging.recoverableException(Types.class, "getDescription", e);
-                }
+    public static String getDescription(final Class<?> type, final Locale locale) {
+        return getDescription(getStandardName(type), locale);
+    }
+
+    /**
+     * Returns the descriptions for the given key in the given locale.
+     *
+     * @param  key     The ISO identifier of a class, or a class property, or a code list
value.
+     * @param  locale  The locale in which to get the description.
+     * @return The description, or {@code null} if none.
+     */
+    static String getDescription(final String key, Locale locale) {
+        if (key != null) {
+            if (locale == null) {
+                locale = Locale.getDefault();
+            }
+            try {
+                return ResourceBundle.getBundle("org.opengis.metadata.Descriptions", locale,
CLASSLOADER).getString(key);
+            } catch (MissingResourceException e) {
+                Logging.recoverableException(Types.class, "getDescription", e);
             }
         }
         return null;



Mime
View raw message