mirror of https://github.com/apache/openjpa.git
Added back the ability to call getPackageName() on the Message object.
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@477446 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
66f6d907d5
commit
15cb2cdf7c
|
@ -78,11 +78,15 @@ public class Localizer {
|
||||||
locale = Locale.getDefault();
|
locale = Locale.getDefault();
|
||||||
|
|
||||||
int dot = (cls == null) ? -1 : cls.getName().lastIndexOf('.');
|
int dot = (cls == null) ? -1 : cls.getName().lastIndexOf('.');
|
||||||
|
String pkg;
|
||||||
String file;
|
String file;
|
||||||
if (dot == -1)
|
if (dot == -1) {
|
||||||
|
pkg = "";
|
||||||
file = "localizer";
|
file = "localizer";
|
||||||
else
|
} else {
|
||||||
file = cls.getName().substring(0, dot + 1) + "localizer";
|
pkg = cls.getName().substring(0, dot);
|
||||||
|
file = pkg + ".localizer";
|
||||||
|
}
|
||||||
String key = file + locale.toString();
|
String key = file + locale.toString();
|
||||||
|
|
||||||
// no locking; ok if bundle created multiple times
|
// no locking; ok if bundle created multiple times
|
||||||
|
@ -91,7 +95,7 @@ public class Localizer {
|
||||||
if (loc != null)
|
if (loc != null)
|
||||||
return loc;
|
return loc;
|
||||||
else {
|
else {
|
||||||
loc = new Localizer(cls, file, locale,
|
loc = new Localizer(pkg, file, locale,
|
||||||
cls == null ? null : cls.getClassLoader());
|
cls == null ? null : cls.getClassLoader());
|
||||||
_localizers.put(key, loc);
|
_localizers.put(key, loc);
|
||||||
return loc;
|
return loc;
|
||||||
|
@ -113,13 +117,13 @@ public class Localizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String _file;
|
private String _file;
|
||||||
|
private String _pkg;
|
||||||
private ResourceBundle _bundle = null;
|
private ResourceBundle _bundle = null;
|
||||||
private Class _cls;
|
|
||||||
private Locale _locale;
|
private Locale _locale;
|
||||||
private ClassLoader _loader;
|
private ClassLoader _loader;
|
||||||
|
|
||||||
private Localizer(Class c, String f, Locale locale, ClassLoader loader) {
|
private Localizer(String pkg, String f, Locale locale, ClassLoader loader) {
|
||||||
_cls = c;
|
_pkg = pkg;
|
||||||
_file = f;
|
_file = f;
|
||||||
_locale = locale;
|
_locale = locale;
|
||||||
_loader = loader;
|
_loader = loader;
|
||||||
|
@ -212,7 +216,7 @@ public class Localizer {
|
||||||
* @see #get(String)
|
* @see #get(String)
|
||||||
*/
|
*/
|
||||||
public Message get(String key, Object[] subs) {
|
public Message get(String key, Object[] subs) {
|
||||||
return new Message(_cls, getBundle(), key, subs, false);
|
return new Message(_pkg, getBundle(), key, subs, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -224,7 +228,7 @@ public class Localizer {
|
||||||
* @see #getFatal(String)
|
* @see #getFatal(String)
|
||||||
*/
|
*/
|
||||||
public Message getFatal(String key, Object[] subs) {
|
public Message getFatal(String key, Object[] subs) {
|
||||||
return new Message(_cls, getBundle(), key, subs, true);
|
return new Message(_pkg, getBundle(), key, subs, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,17 +238,17 @@ public class Localizer {
|
||||||
*/
|
*/
|
||||||
public static class Message {
|
public static class Message {
|
||||||
|
|
||||||
private final Class _cls;
|
private final String _pkg;
|
||||||
private final String _key;
|
private final String _key;
|
||||||
private final Object[] _subs;
|
private final Object[] _subs;
|
||||||
private final String _localizedMessage;
|
private final String _localizedMessage;
|
||||||
|
|
||||||
private Message(Class cls, ResourceBundle bundle, String key,
|
private Message(String packageName, ResourceBundle bundle, String key,
|
||||||
Object[] subs, boolean fatal) {
|
Object[] subs, boolean fatal) {
|
||||||
if (bundle == null && fatal)
|
if (bundle == null && fatal)
|
||||||
throw new MissingResourceException(key, key, key);
|
throw new MissingResourceException(key, key, key);
|
||||||
|
|
||||||
_cls = cls;
|
_pkg = packageName;
|
||||||
_key = key;
|
_key = key;
|
||||||
_subs = subs;
|
_subs = subs;
|
||||||
if (bundle == null) {
|
if (bundle == null) {
|
||||||
|
@ -282,6 +286,10 @@ public class Localizer {
|
||||||
return _subs;
|
return _subs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPackageName() {
|
||||||
|
return _pkg;
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getMessage();
|
return getMessage();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue