Author: desruisseaux
Date: Fri Feb 27 22:58:30 2015
New Revision: 1662849
URL: http://svn.apache.org/r1662849
Log:
When reporting an error about a class, do not show the name of private classes.
Instead, go up in the hierarchy until we find a public class or interface.
Modified:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
Modified:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java?rev=1662849&r1=1662848&r2=1662849&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
[UTF-8] Fri Feb 27 22:58:30 2015
@@ -29,6 +29,7 @@ import java.util.NoSuchElementException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.LogRecord;
+import java.lang.reflect.Modifier;
import org.opengis.util.CodeList;
import org.opengis.util.Enumerated;
import org.opengis.util.InternationalString;
@@ -68,7 +69,7 @@ import org.apache.sis.util.logging.Loggi
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.3
- * @version 0.4
+ * @version 0.6
* @module
*/
public class IndexedResourceBundle extends ResourceBundle implements Localized
{
@@ -404,7 +405,7 @@ public class IndexedResourceBundle exten
}
replacement = message;
} else if (element instanceof Class<?>) {
- replacement = Classes.getShortName((Class<?>) element);
+ replacement = Classes.getShortName(getPublicType((Class<?>)
element));
} else if (element instanceof Enumerated) {
replacement = Types.getCodeTitle((Enumerated)
element).toString(getLocale());
}
@@ -421,6 +422,23 @@ public class IndexedResourceBundle exten
}
/**
+ * If the given class is not public, returns the first public interface or
the first public super-class.
+ * This is for avoiding confusing the user with private class in message
like "Value can not be instance
+ * of XYZ". In the worst case (nothing public other than {@code Object}),
returns {@code Object.class}.
+ */
+ private static Class<?> getPublicType(Class<?> c) {
+ while (!Modifier.isPublic(c.getModifiers())) {
+ for (final Class<?> type : c.getInterfaces()) {
+ if (Modifier.isPublic(type.getModifiers())) {
+ return type;
+ }
+ }
+ c = c.getSuperclass();
+ }
+ return c;
+ }
+
+ /**
* Gets a string for the given key and appends "…" to it.
* This method is typically used for creating menu items.
*