Added support for using a custom classloader when loading message bundles.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3306 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: MessageManager.java,v 1.8 2004/08/27 02:20:36 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -92,6 +92,15 @@ public class MessageManager
|
||||
_cache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows a custom classloader to be configured for locating
|
||||
* translation resources.
|
||||
*/
|
||||
public void setClassLoader (ClassLoader loader)
|
||||
{
|
||||
_loader = loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the message bundle for the specified path. If no bundle can
|
||||
* be located with the specified path, a special bundle is returned
|
||||
@@ -113,7 +122,11 @@ public class MessageManager
|
||||
String fqpath = _prefix + path;
|
||||
ResourceBundle rbundle = null;
|
||||
try {
|
||||
rbundle = ResourceBundle.getBundle(fqpath, _locale);
|
||||
if (_loader != null) {
|
||||
rbundle = ResourceBundle.getBundle(fqpath, _locale, _loader);
|
||||
} else {
|
||||
rbundle = ResourceBundle.getBundle(fqpath, _locale);
|
||||
}
|
||||
} catch (MissingResourceException mre) {
|
||||
Log.warning("Unable to resolve resource bundle " +
|
||||
"[path=" + fqpath + ", locale=" + _locale + "].");
|
||||
@@ -160,6 +173,9 @@ public class MessageManager
|
||||
/** The locale for which we're obtaining message bundles. */
|
||||
protected Locale _locale;
|
||||
|
||||
/** A custom class loader that we use to load resource bundles. */
|
||||
protected ClassLoader _loader;
|
||||
|
||||
/** A cache of instantiated message bundles. */
|
||||
protected HashMap _cache = new HashMap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user