sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1452395 [2/2] - in /sis/trunk: ./ ide-project/NetBeans/nbproject/ sis-metadata/ sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-metadata/src/main/java/org/apache/sis/metadata/ sis-metadata/src/test/ sis-referencing/src/mai...
Date Mon, 04 Mar 2013 16:58:20 GMT
Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/iso/ResourceInternationalString.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/iso/ResourceInternationalString.java?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/iso/ResourceInternationalString.java [UTF-8] (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/iso/ResourceInternationalString.java [UTF-8] Mon Mar  4 16:58:00 2013
@@ -25,34 +25,46 @@ import net.jcip.annotations.Immutable;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 
-// Related to JDK7
-import org.apache.sis.internal.util.Objects;
-
 
 /**
- * An international string backed by a {@linkplain ResourceBundle resource bundle}.
- * A resource bundle can be a Java class or a {@linkplain Properties properties} file,
- * one for each language. The constructor expects the fully qualified class name of the base
- * resource bundle (the one used when no resource was found in the client's language). The appropriate
- * 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.
+ * An international string backed by a {@link ResourceBundle}.
+ * Resource bundles can be Java classes or {@linkplain Properties properties} files, one for each
+ * language. The fully qualified class name of the base resource bundle (without locale suffix)
+ * is specified at {@linkplain #ResourceInternationalString(String, String) construction time}.
+ * The appropriate 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.
+ * See the {@link ResourceBundle#getBundle(String, Locale, ClassLoader) ResourceBundle.getBundle(…)}
+ * Javadoc for more information.
  *
  * {@section Example}
- * If a file named "{@code MyResources.properties}" exists in the package {@code org.mypackage}
- * and contains a line like "{@code MyKey = some value}", then an international string for
- * {@code "some value"} can be created using the following code:
+ * If a file named "{@code MyResources.properties}" exists in {@code org.mypackage}
+ * and contains the following line:
+ *
+ * {@preformat text
+ *     MyKey = some value
+ * }
+ *
+ * Then an international string for {@code "some value"} can be created using the following code:
  *
  * {@preformat java
  *     InternationalString value = new ResourceInternationalString("org.mypackage.MyResources", "MyKey");
  * }
  *
  * The {@code "some value"} string will be localized if the required properties files exist, for
- * example "{@code MyResources_fr.properties}" for French, "{@code MyResources_it.properties}"
+ * example "{@code MyResources_fr.properties}" for French, or "{@code MyResources_it.properties}"
  * for Italian, <i>etc</i>.
  * If needed, users can gain more control by overriding the {@link #getBundle(Locale)} method.
  *
+ * {@section Class loaders}
+ * Developers can specify explicitely the {@link ClassLoader} to use be overriding the
+ * {@link #getBundle(Locale)} method. This is recommended if the running environment
+ * loads modules in isolated class loaders, as OSGi does for instance.
+ *
+ * {@note We do not provide <code>ClassLoader</code> argument in the constructor of this class
+ *        because class loaders can often be hard-coded (thus avoiding the cost of an extra field)
+ *        and are usually not serializable.}
+ *
  * {@section Apache SIS resources}
  * Apache SIS has its own resources mechanism, built on top of the standard {@code ResourceBundle}
  * with the addition of type safety and optional arguments to be formatted in the localized string.
@@ -65,6 +77,8 @@ import org.apache.sis.internal.util.Obje
  * @since   0.3 (derived from geotk-2.1)
  * @version 0.3
  * @module
+ *
+ * @see ResourceBundle#getBundle(String, Locale)
  */
 @Immutable
 public class ResourceInternationalString extends AbstractInternationalString implements Serializable {
@@ -74,33 +88,28 @@ public class ResourceInternationalString
     private static final long serialVersionUID = 6339944890723487336L;
 
     /**
-     * The name of the resource bundle from which to fetch the string.
+     * The name of the resource bundle, as a fully qualified class name.
+     * This value is given at construction time and can not be {@code null}.
      */
-    private final String resources;
+    protected final String resources;
 
     /**
      * The key for the resource to fetch.
+     * This value is given at construction time and can not be {@code null}.
      */
-    private final String key;
+    protected final String key;
 
     /**
-     * The class loader to use for loading the resources file, or {@code null} for the default
-     * class loader.
-     */
-    private final transient ClassLoader loader;
-
-    /**
-     * Creates a new international string from the specified resource bundle, key and class loader.
+     * Creates a new international string from the specified resource bundle and key.
+     * The class loader will be the one of the {@link #toString(Locale)} caller,
+     * unless the {@link #getBundle(Locale)} method is overridden.
      *
      * @param resources The name of the resource bundle, as a fully qualified class name.
-     * @param key The key for the resource to fetch.
-     * @param loader The class loader to use for loading the resources file,
-     *        or {@code null} for the default class loader.
+     * @param key       The key for the resource to fetch.
      */
-    public ResourceInternationalString(final String resources, final String key, final ClassLoader loader) {
+    public ResourceInternationalString(final String resources, final String key) {
         this.resources = resources;
         this.key       = key;
-        this.loader    = loader;
         ensureNonNull("resources", resources);
         ensureNonNull("key",       key);
     }
@@ -110,14 +119,26 @@ public class ResourceInternationalString
      * bundle from the name given at {@linkplain #ResourceInternationalString construction time}.
      * Subclasses can override this method if they need to fetch the bundle in an other way.
      *
+     * {@section Class loaders}
+     * By default, this method loads the resources using the caller's class loader.
+     * Subclasses can override this method in order to specify a different class loader.
+     * For example, the code below works well if {@code MyResource} is a class defined
+     * in the same module than the one that contain the resources to load:
+     *
+     * {@preformat java
+     *     &#64;Override
+     *     protected ResourceBundle getBundle(final Locale locale) {
+     *         return ResourceBundle.getBundle(resources, locale, MyResource.class.getClassLoader());
+     *     }
+     * }
+     *
      * @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, ClassLoader)
      */
     protected ResourceBundle getBundle(final Locale locale) {
-        return (loader == null) ? ResourceBundle.getBundle(resources, locale) :
-                ResourceBundle.getBundle(resources, locale, loader);
+        return ResourceBundle.getBundle(resources, locale);
     }
 
     /**
@@ -152,8 +173,7 @@ public class ResourceInternationalString
     public boolean equals(final Object object) {
         if (object != null && object.getClass() == getClass()) {
             final ResourceInternationalString that = (ResourceInternationalString) object;
-            return Objects.equals(this.key,       that.key) &&
-                   Objects.equals(this.resources, that.resources);
+            return key.equals(that.key) && resources.equals(resources);
         }
         return false;
     }

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8] (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8] Mon Mar  4 16:58:00 2013
@@ -51,8 +51,8 @@ import org.apache.sis.internal.util.Defa
  *       for creating name-related objects from various objects.</li>
  *   <li>{@link #getStandardName(Class)}, {@link #getListName(CodeList)} and {@link #getCodeName(CodeList)}
  *       for fetching ISO names if possible.</li>
- *   <li>{@link #getCodeTitle(CodeList, Locale)}, {@link #getDescription(CodeList, Locale)} and
- *       {@link #getDescription(Class, Locale)} for fetching human-readable descriptions.</li>
+ *   <li>{@link #getCodeTitle(CodeList)}, {@link #getDescription(CodeList)} and
+ *       {@link #getDescription(Class)} for fetching human-readable descriptions.</li>
  *   <li>{@link #forStandardName(String)} and {@link #forCodeName(Class, String, boolean)} for
  *       fetching an instance from a name (converse of above {@code get} methods).</li>
  * </ul>
@@ -64,13 +64,6 @@ import org.apache.sis.internal.util.Defa
  */
 public final class Types extends Static {
     /**
-     * The class loader to use for fetching GeoAPI resources.
-     * Since the resources are bundled in the GeoAPI JAR file,
-     * we use the instance that loaded GeoAPI for more determinist behavior.
-     */
-    private 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.
      * This map will be built only when first needed.
@@ -159,8 +152,9 @@ public final class Types extends Static 
      * @return The UML identifiers or programmatic name for the given code,
      *         or {@code null} if the given code is null.
      *
+     * @see #getCodeLabel(CodeList)
      * @see #getCodeTitle(CodeList)
-     * @see #getDescription(CodeList, Locale)
+     * @see #getDescription(CodeList)
      * @see #forCodeName(Class, String, boolean)
      */
     public static String getCodeName(final CodeList<?> code) {
@@ -175,7 +169,7 @@ public final class Types extends Static 
      * Returns a unlocalized title for the given code.
      * This method builds a title using heuristics rules, which should give reasonable
      * results without the need of resource bundles. For better results, consider using
-     * {@link #getCodeTitle(CodeList, Locale)} instead.
+     * {@link #getCodeTitle(CodeList)} instead.
      *
      * <p>The current heuristic implementation iterates over {@linkplain CodeList#names() all
      * code names}, selects the longest one excluding the {@linkplain CodeList#name() field name}
@@ -183,18 +177,19 @@ public final class Types extends Static 
      * from that name. Examples:</p>
      *
      * <ul>
-     *   <li>{@code getCodeTitle(AxisDirection.NORTH)} returns {@code "North"}.</li>
-     *   <li>{@code getCodeTitle(CharacterSet.UTF_8)} returns {@code "UTF-8"}.</li>
-     *   <li>{@code getCodeTitle(ImagingCondition.BLURRED_IMAGE)} returns {@code "Blurred image"}.</li>
+     *   <li>{@code getCodeLabel(AxisDirection.NORTH)} returns {@code "North"}.</li>
+     *   <li>{@code getCodeLabel(CharacterSet.UTF_8)} returns {@code "UTF-8"}.</li>
+     *   <li>{@code getCodeLabel(ImagingCondition.BLURRED_IMAGE)} returns {@code "Blurred image"}.</li>
      * </ul>
      *
      * @param  code The code from which to get a title, or {@code null}.
      * @return A unlocalized title for the given code, or {@code null} if the given code is null.
      *
      * @see #getCodeName(CodeList)
-     * @see #getDescription(CodeList, Locale)
+     * @see #getCodeTitle(CodeList)
+     * @see #getDescription(CodeList)
      */
-    public static String getCodeTitle(final CodeList<?> code) {
+    public static String getCodeLabel(final CodeList<?> code) {
         if (code == null) {
             return null;
         }
@@ -212,120 +207,197 @@ public final class Types extends Static 
     }
 
     /**
-     * Returns the localized title of the given code.
-     * Special cases:
-     *
-     * <ul>
-     *   <li>If {@code code} is {@code null}, then this method returns {@code null}.</li>
-     *   <li>If {@code locale} is {@code null}, then this method uses {@link Locale#ROOT}
-     *       for "unlocalized" (typically English) strings.</li>
-     *   <li>If there is no resources for the given code in the given language, then this method
-     *       fallback on other languages as described in {@link ResourceBundle} javadoc.</li>
-     *   <li>If there is no localized resources for the given code, then this method fallback
-     *       on {@link #getCodeTitle(CodeList)}.</li>
-     * </ul>
+     * Returns the title of the given code. Title are usually much shorter than descriptions.
+     * English titles are often the same than the {@linkplain #getCodeLabel(CodeList) code labels}.
      *
-     * @param  code   The code for which to get the localized name, or {@code null}.
-     * @param  locale The local, or {@code null} if none.
-     * @return The localized title, or {@code null} if the given code is null.
+     * @param  code The code for which to get the title, or {@code null}.
+     * @return The title, or {@code null} if the given code is null.
      *
-     * @see #getDescription(CodeList, Locale)
+     * @see #getDescription(CodeList)
      */
-    public static String getCodeTitle(final CodeList<?> code, Locale locale) {
-        if (code == null) {
-            return null;
-        }
-        if (locale == null) {
-            locale = Locale.ROOT;
-        }
-        /*
-         * The code below is a duplicated - in a different way - of CodeListProxy(CodeList)
-         * constructor (org.apache.sis.internal.jaxb.code package). This duplication exists
-         * because CodeListProxy constructor stores more information in an opportunist way.
-         * If this method is updated, please update CodeListProxy(CodeList) accordingly.
-         */
-        final String key = getListName(code) + '.' + getCodeName(code);
-        try {
-            return ResourceBundle.getBundle("org.opengis.metadata.CodeLists", locale, CLASSLOADER).getString(key);
-        } catch (MissingResourceException e) {
-            Logging.recoverableException(Types.class, "getCodeTitle", e);
-            return getCodeTitle(code);
-        }
+    public static InternationalString getCodeTitle(final CodeList<?> code) {
+        return (code != null) ? new CodeTitle(code) : null;
     }
 
     /**
-     * Returns the localized description of the given code, or {@code null} if none.
-     * Special cases:
-     *
-     * <ul>
-     *   <li>If {@code code} is {@code null}, then this method returns {@code null}.</li>
-     *   <li>If {@code locale} is {@code null}, then this method uses the
-     *       {@linkplain Locale#getDefault() default locale} - there is no such thing
-     *       like "unlocalized" description.</li>
-     *   <li>If there is no resources for the given code in the given language, then this method
-     *       fallback on other languages as described in {@link ResourceBundle} javadoc.</li>
-     *   <li>If there is no localized resources for the given code, then this method returns
-     *       {@code null} - there is no fallback.</li>
-     * </ul>
-     *
+     * Returns the description of the given code, or {@code null} if none.
      * For a description of the code list as a whole instead than a particular code,
-     * see {@link Types#getDescription(Class, Locale)}.
+     * see {@link Types#getDescription(Class)}.
      *
-     * @param  code   The code for which to get the localized description, or {@code null}.
-     * @param  locale The desired local, or {@code null} for the default locale.
-     * @return The localized description, or {@code null} if the given code is null.
+     * @param  code The code for which to get the localized description, or {@code null}.
+     * @return The description, or {@code null} if none or if the given code is null.
      *
-     * @see #getCodeTitle(CodeList, Locale)
-     * @see #getDescription(Class, Locale)
+     * @see #getCodeTitle(CodeList)
+     * @see #getDescription(Class)
      */
-    public static String getDescription(final CodeList<?> code, final Locale locale) {
-        return (code != null) ? getDescription(getListName(code) + '.' + getCodeName(code), locale) : null;
+    public static InternationalString getDescription(final CodeList<?> code) {
+        if (code != null) {
+            final String resources = getResources(code.getClass().getName());
+            if (resources != null) {
+                return new Description(resources, getListName(code) + '.' + getCodeName(code));
+            }
+        }
+        return null;
     }
 
     /**
-     * Returns a localized description for the given class, or {@code null} if none.
+     * Returns a description for the given class, or {@code null} if none.
      * This method can be used for GeoAPI interfaces or {@link CodeList}.
-     * Special cases:
-     *
-     * <ul>
-     *   <li>If {@code code} is {@code null}, then this method returns {@code null}.</li>
-     *   <li>If {@code locale} is {@code null}, then this method uses the
-     *       {@linkplain Locale#getDefault() default locale} - there is no such thing
-     *       like "unlocalized" description.</li>
-     *   <li>If there is no resources for the given type in the given language, then this method
-     *       fallback on other languages as described in {@link ResourceBundle} javadoc.</li>
-     *   <li>If there is no localized resources for the given type, then this method returns
-     *       {@code null} - there is no fallback.</li>
-     * </ul>
      *
      * @param  type The GeoAPI interface or code list from which to get the description, or {@code null}.
-     * @param  locale The desired local, or {@code null} for the default locale.
-     * @return The ISO name for the given type, or {@code null} if none or if the type is {@code null}.
+     * @return The description, or {@code null} if none or if the given type is {@code null}.
      *
-     * @see #getDescription(CodeList, Locale)
+     * @see #getDescription(CodeList)
      */
-    public static String getDescription(final Class<?> type, final Locale locale) {
-        return getDescription(getStandardName(type), locale);
+    public static InternationalString getDescription(final Class<?> type) {
+        final String name = getStandardName(type);
+        if (name != null) {
+            final String resources = getResources(type.getName());
+            if (resources != null) {
+                return new Description(resources, name);
+            }
+        }
+        return null;
     }
 
     /**
-     * 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.
-     */
-    private static String getDescription(final String key, Locale locale) {
-        if (key != null) {
-            if (locale == null) {
-                locale = Locale.getDefault();
+     * Returns a description for the given property, or {@code null} if none.
+     * The given type shall be a GeoAPI interface, and the given property shall
+     * be a UML identifier. If any of the input argument is {@code null}, then
+     * this method returns {@code null}.
+     *
+     * @param  type     The GeoAPI interface from which to get the description of a property, or {@code null}.
+     * @param  property The ISO name of the property for which to get the description, or {@code null}.
+     * @return The description, or {@code null} if none or if the given type or property name is {@code null}.
+     */
+    public static InternationalString getDescription(final Class<?> type, final String property) {
+        if (property != null) {
+            final String name = getStandardName(type);
+            if (name != null) {
+                final String resources = getResources(type.getName());
+                if (resources != null) {
+                    return new Description(resources, name + '.' + property);
+                }
             }
+        }
+        return null;
+    }
+
+    /**
+     * The {@link InternationalString} returned by the {@code Types.getDescription(…)} methods.
+     *
+     * @author  Martin Desruisseaux (Geomatys)
+     * @since   0.3
+     * @version 0.3
+     * @module
+     */
+    private static class Description extends ResourceInternationalString {
+        /**
+         * For cross-version compatibility.
+         */
+        private static final long serialVersionUID = 7336442452947376873L;
+
+        /**
+         * The class loader to use for fetching GeoAPI resources.
+         * Since the resources are bundled in the GeoAPI JAR file,
+         * we use the instance that loaded GeoAPI for more determinist behavior.
+         */
+        private static final ClassLoader CLASSLOADER = UML.class.getClassLoader();
+
+        /**
+         * 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.
+         */
+        Description(final String resources, final String key) {
+            super(resources, key);
+        }
+
+        /**
+         * Loads the resources using the class loader used for loading GeoAPI interfaces.
+         */
+        @Override
+        protected final ResourceBundle getBundle(final Locale locale) {
+            return ResourceBundle.getBundle(resources, locale, CLASSLOADER);
+        }
+
+        /**
+         * Returns the description for the given locale, or fallback on a default description
+         * if no resources exist for that locale.
+         */
+        @Override
+        public final String toString(final Locale locale) {
             try {
-                return ResourceBundle.getBundle("org.opengis.metadata.Descriptions", locale, CLASSLOADER).getString(key);
+                return super.toString(locale);
             } catch (MissingResourceException e) {
-                Logging.recoverableException(Types.class, "getDescription", e);
+                Logging.recoverableException(ResourceInternationalString.class, "toString", e);
+                return fallback();
             }
         }
+
+        /**
+         * Returns a fallback if no resource is found.
+         */
+        String fallback() {
+            return CharSequences.camelCaseToSentence(key.substring(key.lastIndexOf('.') + 1)).toString();
+        }
+    }
+
+    /**
+     * The {@link InternationalString} returned by the {@code Types.getCodeTitle(…)} method.
+     * The code below is a duplicated - in a different way - of {@code CodeListProxy(CodeList)}
+     * constructor ({@link org.apache.sis.internal.jaxb.code package}). This duplication exists
+     * because {@code CodeListProxy} constructor stores more information in an opportunist way.
+     * If this method is updated, please update {@code CodeListProxy(CodeList)} accordingly.
+     *
+     * @author  Martin Desruisseaux (Geomatys)
+     * @since   0.3
+     * @version 0.3
+     * @module
+     */
+    private static final class CodeTitle extends Description {
+        /**
+         * For cross-version compatibility.
+         */
+        private static final long serialVersionUID = 3306532357801489365L;
+
+        /**
+         * The code list for which to create a title.
+         */
+        private final CodeList<?> code;
+
+        /**
+         * Creates a new international string for the given code list element.
+         *
+         * @param code The code list for which to create a title.
+         */
+        CodeTitle(final CodeList<?> code) {
+            super("org.opengis.metadata.CodeLists", getListName(code) + '.' + getCodeName(code));
+            this.code = code;
+        }
+
+        /**
+         * Returns a fallback if no resource is found.
+         */
+        @Override
+        String fallback() {
+            return getCodeLabel(code);
+        }
+    }
+
+    /**
+     * Returns the resource name for the given GeoAPI type, or {@code null} if none.
+     *
+     * @param  classname The fully qualified name of the GeoAPI type.
+     * @return The resource bundle to load, or {@code null} if none.
+     */
+    static String getResources(final String classname) {
+        String resources = "org.opengis.metadata.Descriptions";
+        if (classname.regionMatches(0, resources, 0, 21)) { // 21 is the location after the last dot.
+            return resources;
+        }
+        // Add more checks here (maybe in a loop) if there is more resource candidates.
         return null;
     }
 

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] Mon Mar  4 16:58:00 2013
@@ -68,6 +68,26 @@ public final class Errors extends Indexe
         public static final int CanNotComputeDerivative = 44;
 
         /**
+         * Can not convert from type ‘{0}’ to type ‘{1}’.
+         */
+        public static final int CanNotConvertFromType_2 = 72;
+
+        /**
+         * Can not convert value “{0}” to type ‘{1}’.
+         */
+        public static final int CanNotConvertValue_2 = 74;
+
+        /**
+         * Can not set a value for property “{0}”.
+         */
+        public static final int CanNotSetPropertyValue_1 = 75;
+
+        /**
+         * Class ‘{0}’ is not final.
+         */
+        public static final int ClassNotFinal_1 = 71;
+
+        /**
          * Can not clone an object of type ‘{0}’.
          */
         public static final int CloneNotSupported_1 = 42;
@@ -240,6 +260,11 @@ public final class Errors extends Indexe
         public static final int NegativeArgument_2 = 8;
 
         /**
+         * No property named “{0}” has been found in “{1}”.
+         */
+        public static final int NoSuchProperty_2 = 73;
+
+        /**
          * No unit of measurement has been specified.
          */
         public static final int NoUnit = 68;
@@ -355,6 +380,11 @@ public final class Errors extends Indexe
         public static final int UnexpectedEndOfString_1 = 30;
 
         /**
+         * Type ‘{0}’ is unknown in this context.
+         */
+        public static final int UnknownType_1 = 76;
+
+        /**
          * This affine transform is unmodifiable.
          */
         public static final int UnmodifiableAffineTransform = 23;

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] Mon Mar  4 16:58:00 2013
@@ -24,8 +24,11 @@
 # programmatic parameters do not have to be last in the formatted text, since each localized message
 # can reorder the parameters as they want.
 #
-
+CanNotConvertFromType_2         = Can not convert from type \u2018{0}\u2019 to type \u2018{1}\u2019.
+CanNotConvertValue_2            = Can not convert value \u201c{0}\u201d to type \u2018{1}\u2019.
 CanNotComputeDerivative         = Can not compute the derivative.
+CanNotSetPropertyValue_1        = Can not set a value for property \u201c{0}\u201d.
+ClassNotFinal_1                 = Class \u2018{0}\u2019 is not final.
 CloneNotSupported_1             = Can not clone an object of type \u2018{0}\u2019.
 DeadThread_1                    = Thread \u201c{0}\u201d is dead.
 DuplicatedValue_1               = Value \u201c{0}\u201d is duplicated.
@@ -72,6 +75,7 @@ NonTemporalUnit_1               = \u201c
 NotANumber_1                    = Argument \u2018{0}\u2019 shall not be NaN (Not-a-Number).
 NotAPrimitiveWrapper_1          = Class \u2018{0}\u2019 is not a primitive type wrapper.
 NotComparableClass_1            = Class \u2018{0}\u2019 is not a comparable.
+NoSuchProperty_2                = No property named \u201c{0}\u201d has been found in \u201c{1}\u201d.
 NoUnit                          = No unit of measurement has been specified.
 NullArgument_1                  = Argument \u2018{0}\u2019 shall not be null.
 # Use the OGC/ISO "Dictionary" word instead of "Map" for avoiding confusion with geographic map.
@@ -84,6 +88,7 @@ StalledThread_1                 = Thread
 UndefinedOrderingForElements_2  = Ordering between \u201c{0}\u201d and \u201c{1}\u201d elements is undefined.
 UnexpectedChange_1              = Unexpected change in \u2018{0}\u2019.
 UnexpectedEndOfString_1         = More characters were expected at the end of \u201c{0}\u201d.
+UnknownType_1                   = Type \u2018{0}\u2019 is unknown in this context.
 UnmodifiableAffineTransform     = This affine transform is unmodifiable.
 UnmodifiableGeometry            = This geometry is unmodifiable.
 UnmodifiableMetadata            = This metadata is unmodifiable.

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] Mon Mar  4 16:58:00 2013
@@ -14,7 +14,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+CanNotConvertFromType_2         = Ne peut pas convertir du type \u2018{0}\u2019 vers le type \u2018{1}\u2019.
+CanNotConvertValue_2            = La valeur \u201c{0}\u201d ne peut pas \u00eatre convertie vers le type \u2018{1}\u2019.
 CanNotComputeDerivative         = La d\u00e9riv\u00e9 ne peut pas \u00eatre calcul\u00e9e.
+CanNotSetPropertyValue_1        = Ne peut pas d\u00e9finir une valeur pour la propri\u00e9t\u00e9 \u201c{0}\u201d.
+ClassNotFinal_1                 = La classe \u2018{0}\u2019 n\u2019est pas finale.
 CloneNotSupported_1             = Un objet de type \u2018{0}\u2019 ne peut pas \u00eatre clon\u00e9.
 DeadThread_1                    = La t\u00e2che \u201c{0}\u201d est morte.
 DuplicatedValue_1               = La valeur \u201c{0}\u201d est dupliqu\u00e9e.
@@ -61,6 +65,7 @@ NonTemporalUnit_1               = \u201c
 NotANumber_1                    = L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre NaN (Not-a-Number).
 NotAPrimitiveWrapper_1          = La classe \u2018{0}\u2019 n\u2019est pas un adaptateur d\u2019un type primitif.
 NotComparableClass_1            = La classe \u2018{0}\u2019 n\u2019est pas comparable.
+NoSuchProperty_2                = Aucune propri\u00e9t\u00e9 nomm\u00e9e \u201c{0}\u201d n\u2019a \u00e9t\u00e9 trouv\u00e9e dans \u201c{1}\u201d.
 NoUnit                          = Aucune unit\u00e9 de mesure n\u2019a \u00e9t\u00e9 sp\u00e9cifi\u00e9e.
 NullArgument_1                  = L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre nul.
 NullMapKey                      = La cl\u00e9 nulle n\u2019est pas autoris\u00e9e dans ce dictionnaire.
@@ -72,6 +77,7 @@ StalledThread_1                 = La t\u
 UndefinedOrderingForElements_2  = L\u2019ordre entre les \u00e9l\u00e9ments \u201c{0}\u201d et \u201c{1}\u201d n\u2019est pas d\u00e9fini.
 UnexpectedChange_1              = Changement inattendu dans \u2018{0}\u2019.
 UnexpectedEndOfString_1         = D\u2019autres caract\u00e8res \u00e9taient attendus \u00e0 la fin du texte \u201c{0}\u201d.
+UnknownType_1                   = Le type \u2018{0}\u2019 n\u2019est pas reconnu dans ce contexte.
 UnmodifiableAffineTransform     = Cette transformation affine n\u2019est pas modifiable.
 UnmodifiableGeometry            = Cette g\u00e9om\u00e9trie n\u2019est pas modifiable.
 UnmodifiableMetadata            = Cette m\u00e9ta-donn\u00e9e n\u2019est pas modifiable.

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java [UTF-8] (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/measure/NumberRangeTest.java [UTF-8] Mon Mar  4 16:58:00 2013
@@ -31,7 +31,10 @@ import static org.junit.Assert.*;
  * @version 0.3
  * @module
  */
-@DependsOn(RangeTest.class)
+@DependsOn({
+    RangeTest.class,
+    org.apache.sis.util.NumbersTest.class
+})
 public final strictfp class NumberRangeTest extends TestCase {
     /**
      * Tests the endpoint values of a range of integers.
@@ -116,4 +119,20 @@ public final strictfp class NumberRangeT
         assertEquals(NumberRange.create((short) 2, true, (short) 200, true),
                 NumberRange.createBestFit(2, true, 200.0, true));
     }
+
+    /**
+     * Tests the construction using the {@link ValueRange} annotation.
+     * The annotation used for this test is declared on this test method.
+     *
+     * @throws NoSuchMethodException Should never happen.
+     */
+    @Test
+    @ValueRange(minimum=4, maximum=8, isMaxIncluded=false)
+    public void testValueRangeAnnotation() throws NoSuchMethodException {
+        final ValueRange values = NumberRangeTest.class
+                .getMethod("testValueRangeAnnotation").getAnnotation(ValueRange.class);
+        assertNotNull("Annotation not found.", values);
+        final NumberRange<Short> range = new NumberRange<Short>(Short.class, values);
+        assertEquals(NumberRange.create((short) 4, true, (short) 8, false), range);
+    }
 }

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/test/TestCase.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/test/TestCase.java?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8] (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8] Mon Mar  4 16:58:00 2013
@@ -80,7 +80,6 @@ public abstract strictfp class TestCase 
      * property has been set to a different value.
      *
      * @see org.apache.sis.test
-     * @see #flushVerboseOutput()
      */
     public static final PrintWriter out;
 

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java [UTF-8] (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java [UTF-8] Mon Mar  4 16:58:00 2013
@@ -60,6 +60,7 @@ import org.junit.runners.Suite;
     org.apache.sis.util.collection.TableColumnTest.class,
     org.apache.sis.util.collection.DefaultTreeTableTest.class,
     org.apache.sis.util.collection.TreeTablesTest.class,
+    org.apache.sis.util.collection.CodeListSetTest.class,
 
     // GeoAPI most basic types.
     org.apache.sis.util.iso.TypesTest.class,

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ClassesTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ClassesTest.java?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ClassesTest.java [UTF-8] (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/util/ClassesTest.java [UTF-8] Mon Mar  4 16:58:00 2013
@@ -185,30 +185,30 @@ public final strictfp class ClassesTest 
     }
 
     /**
-     * Tests the {@link Classes#boundOfParameterizedAttribute(Field)} method.
+     * Tests the {@link Classes#boundOfParameterizedProperty(Field)} method.
      *
      * @throws NoSuchFieldException  Should never occur.
      * @throws NoSuchMethodException Should never occur.
      */
     @Test
-    public void testBoundOfParameterizedAttribute() throws NoSuchFieldException, NoSuchMethodException {
+    public void testBoundOfParameterizedProperty() throws NoSuchFieldException, NoSuchMethodException {
         final Class<?>[] g = null;
         final Class<?>[] s = new Class<?>[] {Set.class};
         final Class<Parameterized> c = Parameterized.class;
-        assertNull(                 boundOfParameterizedAttribute(c.getMethod("getter0", g)));
-        assertNull(                 boundOfParameterizedAttribute(c.getMethod("setter0", s)));
-        assertEquals(Long   .class, boundOfParameterizedAttribute(c.getField ("attrib2"   )));
-        assertEquals(Integer.class, boundOfParameterizedAttribute(c.getMethod("getter1", g)));
-        assertEquals(Byte   .class, boundOfParameterizedAttribute(c.getMethod("getter2", g)));
-        assertEquals(Object .class, boundOfParameterizedAttribute(c.getMethod("getter3", g)));
-        assertEquals(short[].class, boundOfParameterizedAttribute(c.getMethod("getter4", g)));
-        assertEquals(String .class, boundOfParameterizedAttribute(c.getMethod("setter1", s)));
-        assertEquals(Short  .class, boundOfParameterizedAttribute(c.getMethod("setter2", s)));
-        assertEquals(Object .class, boundOfParameterizedAttribute(c.getMethod("setter3", s)));
+        assertNull(                 boundOfParameterizedProperty(c.getMethod("getter0", g)));
+        assertNull(                 boundOfParameterizedProperty(c.getMethod("setter0", s)));
+        assertEquals(Long   .class, boundOfParameterizedProperty(c.getField ("attrib2"   )));
+        assertEquals(Integer.class, boundOfParameterizedProperty(c.getMethod("getter1", g)));
+        assertEquals(Byte   .class, boundOfParameterizedProperty(c.getMethod("getter2", g)));
+        assertEquals(Object .class, boundOfParameterizedProperty(c.getMethod("getter3", g)));
+        assertEquals(short[].class, boundOfParameterizedProperty(c.getMethod("getter4", g)));
+        assertEquals(String .class, boundOfParameterizedProperty(c.getMethod("setter1", s)));
+        assertEquals(Short  .class, boundOfParameterizedProperty(c.getMethod("setter2", s)));
+        assertEquals(Object .class, boundOfParameterizedProperty(c.getMethod("setter3", s)));
     }
 
     /**
-     * Dummy class for {@link #testBoundOfParameterizedAttribute()} usage only.
+     * Dummy class for {@link #testBoundOfParameterizedProperty()} usage only.
      */
     private static final class Parameterized {
         public Set<? extends Long> attrib2 = null;

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/util/NumbersTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/NumbersTest.java?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/util/NumbersTest.java [UTF-8] (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/util/NumbersTest.java [UTF-8] Mon Mar  4 16:58:00 2013
@@ -174,7 +174,33 @@ public final class NumbersTest extends T
      */
     @Test
     public void testCast() {
-        assertEquals(Byte .valueOf((byte)  10), cast(Integer.valueOf(10), Byte .class));
-        assertEquals(Float.valueOf((float) 10), cast(Integer.valueOf(10), Float.class));
+        final Integer value = new Integer(10); // Intentionally a new instance.
+        assertEquals(Byte   .valueOf((byte)   10), cast(value, Byte   .class));
+        assertEquals(Short  .valueOf((short)  10), cast(value, Short  .class));
+        assertSame  (value,                        cast(value, Integer.class));
+        assertEquals(Long   .valueOf((long)   10), cast(value, Long   .class));
+        assertEquals(Float  .valueOf((float)  10), cast(value, Float  .class));
+        assertEquals(Double .valueOf((double) 10), cast(value, Double .class));
+    }
+
+    /**
+     * Tests {@link Numbers#wrap(double, Class)}.
+     */
+    @Test
+    public void testWrap() {
+        final double value = 10;
+        assertEquals(Byte   .valueOf((byte)   10), wrap(value, Byte   .class));
+        assertEquals(Short  .valueOf((short)  10), wrap(value, Short  .class));
+        assertEquals(Integer.valueOf(         10), wrap(value, Integer.class));
+        assertEquals(Long   .valueOf((long)   10), wrap(value, Long   .class));
+        assertEquals(Float  .valueOf((float)  10), wrap(value, Float  .class));
+        assertEquals(Double .valueOf((double) 10), wrap(value, Double .class));
+        try {
+            final Integer n = wrap(4.5, Integer.class);
+            fail("Expected an exception but got " + n);
+        } catch (IllegalArgumentException e) {
+            // This is the expected exception.
+            assertTrue(e.getMessage().contains("Integer"));
+        }
     }
 }

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java [UTF-8] (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/util/collection/CacheTest.java [UTF-8] Mon Mar  4 16:58:00 2013
@@ -297,15 +297,19 @@ public final strictfp class CacheTest ex
         }
         out.println();
         /*
-         * Gets the statistics of key values after garbage collection. The mean value should
+         * Gets the statistics of key values after garbage collection. Most values should
          * be higher, because oldest values (which should have been garbage collected first)
          * have lower values. If verbose output is enabled, then we will print the statistics
          * before to perform the actual check in order to allow the developer to have more
          * information in case of failure.
+         *
+         * The mean value is often greater, but not always. Since we have fewer remaining values
+         * (100 instead of 10000), the remaining low values will have a much greater impact on
+         * the mean. Only the check on the minimal value is fully reliable.
          */
         final Statistics afterGC = validateStressEntries("After GC", cache);
         out.println("Statistics on the keys before and after garbage collection.");
-        out.println("The minimum and the mean values should be greater after GC.");
+        out.println("The minimum value should be greater after GC.");
         final StatisticsFormat format = StatisticsFormat.getInstance();
         format.setBorderWidth(1);
         try {
@@ -313,6 +317,7 @@ public final strictfp class CacheTest ex
         } catch (IOException e) {
             throw new AssertionError(e);
         }
-        assertTrue("Mean key value should be greater after garbage collection.", afterGC.mean() >= beforeGC.mean());
+        assertTrue("Minimum key value should be greater after garbage collection.",
+                afterGC.minimum() >= beforeGC.minimum());
     }
 }

Modified: sis/trunk/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java?rev=1452395&r1=1452394&r2=1452395&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java [UTF-8] (original)
+++ sis/trunk/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java [UTF-8] Mon Mar  4 16:58:00 2013
@@ -20,6 +20,8 @@ import java.util.Set;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Locale;
+import org.opengis.util.InternationalString;
+import org.opengis.metadata.citation.Address;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.citation.OnLineFunction;
 import org.opengis.metadata.content.ImagingCondition;
@@ -76,29 +78,51 @@ public final strictfp class TypesTest ex
     }
 
     /**
-     * Tests the {@link Types#getDescription(Class, Locale)} method.
+     * Tests the {@link Types#getResources(String)} method.
+     */
+    @Test
+    public void testGetResources() {
+        assertEquals("org.opengis.metadata.Descriptions", Types.getResources("org.opengis.metadata.Identifier"));
+        assertNull(Types.getResources("org.opengis.metadata2.Identifier"));
+    }
+
+    /**
+     * Tests the {@link Types#getDescription(Class)} method.
      */
     @Test
     public void testGetDescription() {
+        final InternationalString description = Types.getDescription(CharacterSet.class);
         assertEquals("Name of the character coding standard used in the resource.",
-                Types.getDescription(CharacterSet.class, Locale.ROOT));
+                description.toString(Locale.ROOT));
         assertEquals("Name of the character coding standard used in the resource.",
-                Types.getDescription(CharacterSet.class, Locale.ENGLISH));
+                description.toString(Locale.ENGLISH));
         assertEquals("Jeu de caractères.",
-                Types.getDescription(CharacterSet.class, Locale.FRENCH));
+                description.toString(Locale.FRENCH));
+    }
+
+    /**
+     * Tests the {@link Types#getDescription(Class, String)} method.
+     */
+    @Test
+    public void testGetPropertyDescription() {
+        assertEquals("The city of the location.",
+                Types.getDescription(Address.class, "city").toString(Locale.ROOT));
+        assertEquals("Country of the physical address.",
+                Types.getDescription(Address.class, "country").toString(Locale.ENGLISH));
     }
 
     /**
-     * Tests the {@link Types#getDescription(CodeList, Locale)} method.
+     * Tests the {@link Types#getDescription(CodeList)} method.
      */
     @Test
     public void testGetCodeDescription() {
+        final InternationalString description = Types.getDescription(CharacterSet.ISO_8859_1);
         assertEquals("ISO/IEC 8859-1, Information technology - 8-bit single byte coded graphic character sets - Part 1 : Latin alphabet No.1.",
-                Types.getDescription(CharacterSet.ISO_8859_1, Locale.ROOT));
+                description.toString(Locale.ROOT));
         assertEquals("ISO/IEC 8859-1, Information technology - 8-bit single byte coded graphic character sets - Part 1 : Latin alphabet No.1.",
-                Types.getDescription(CharacterSet.ISO_8859_1, Locale.ENGLISH));
+                description.toString(Locale.ENGLISH));
         assertEquals("ISO/IEC 8859-1, alphabet latin 1.",
-                Types.getDescription(CharacterSet.ISO_8859_1, Locale.FRENCH));
+                description.toString(Locale.FRENCH));
     }
 
     /**
@@ -122,23 +146,23 @@ public final strictfp class TypesTest ex
     }
 
     /**
-     * Tests the examples given in {@link Types#getCodeTitle(CodeList)} javadoc.
+     * Tests the examples given in {@link Types#getCodeLabel(CodeList)} javadoc.
      */
     @Test
-    public void testGetCodeTitle() {
-        assertEquals("North",         Types.getCodeTitle(AxisDirection   .NORTH));
-        assertEquals("UTF-8",         Types.getCodeTitle(CharacterSet    .UTF_8));
-        assertEquals("Blurred image", Types.getCodeTitle(ImagingCondition.BLURRED_IMAGE));
+    public void testGetCodeLabel() {
+        assertEquals("North",         Types.getCodeLabel(AxisDirection   .NORTH));
+        assertEquals("UTF-8",         Types.getCodeLabel(CharacterSet    .UTF_8));
+        assertEquals("Blurred image", Types.getCodeLabel(ImagingCondition.BLURRED_IMAGE));
     }
 
     /**
-     * Tests {@link Types#getCodeTitle(CodeList, Locale)}.
+     * Tests {@link Types#getCodeTitle(CodeList)}.
      */
     @Test
-    public void testGetLocalizedCodeTitle() {
-        assertEquals("Download",       Types.getCodeTitle(OnLineFunction.DOWNLOAD, Locale.ROOT));
-        assertEquals("Download",       Types.getCodeTitle(OnLineFunction.DOWNLOAD, Locale.ENGLISH));
-        assertEquals("Téléchargement", Types.getCodeTitle(OnLineFunction.DOWNLOAD, Locale.FRENCH));
+    public void testGetCodeTitle() {
+        assertEquals("Download",       Types.getCodeTitle(OnLineFunction.DOWNLOAD).toString(Locale.ROOT));
+        assertEquals("Download",       Types.getCodeTitle(OnLineFunction.DOWNLOAD).toString(Locale.ENGLISH));
+        assertEquals("Téléchargement", Types.getCodeTitle(OnLineFunction.DOWNLOAD).toString(Locale.FRENCH));
     }
 
     /**



Mime
View raw message