From 69fd36030f38ff63352338ae5cf42b047f3adfe3 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 20 Jan 2005 16:32:10 +0000 Subject: [PATCH] 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 --- .../com/threerings/util/MessageManager.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/util/MessageManager.java b/src/java/com/threerings/util/MessageManager.java index 9f17b424a..36600c946 100644 --- a/src/java/com/threerings/util/MessageManager.java +++ b/src/java/com/threerings/util/MessageManager.java @@ -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();