Package org.eigenbase.resgen
Class ShadowResourceBundle
- java.lang.Object
-
- java.util.ResourceBundle
-
- org.eigenbase.resgen.ShadowResourceBundle
-
public abstract class ShadowResourceBundle extends java.util.ResourceBundleShadowResourceBundleis an abstract base class forResourceBundleclasses which are backed by a properties file. When the class is created, it loads a properties file with the same name as the class.In the standard scheme (see
ResourceBundle), if you call, it first looks for a class calledResourceBundle.getBundle(java.lang.String)("foo.MyResource")foo.MyResource, then looks for a file calledfoo/MyResource.properties. If it finds the file, it creates aPropertyResourceBundleand loads the class. The problem is if you want to load the.propertiesfile into a dedicated class;ShadowResourceBundlehelps with this case.You should create a class as follows:
Then when you callpackage foo; class MyResource extends org.eigenbase.resgen.ShadowResourceBundle { public MyResource() throws java.io.IOException { } }ResourceBundle.getBundle("foo.MyResource"), it will find the class before the properties file, but still automatically load the properties file based upon the name of the class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classShadowResourceBundle.MyPropertyResourceBundle
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.Object[]emptyObjectArray
-
Constructor Summary
Constructors Modifier Constructor Description protectedShadowResourceBundle()Creates aShadowResourceBundle, and reads resources from a.propertiesfile with the same name as the current class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.EnumerationgetKeys()static java.util.LocalegetThreadLocale()Returns the preferred locale of the current thread, or null if the thread has not calledsetThreadLocale(java.util.Locale).protected static java.util.LocalegetThreadOrDefaultLocale()Returns the preferred locale of the current thread, or the default locale if the current thread has not calledsetThreadLocale(java.util.Locale).protected java.lang.ObjecthandleGetObject(java.lang.String key)protected static java.util.ResourceBundleinstance(java.lang.String baseName)Deprecated.This method does not work correctly in dynamically loaded jars.protected static ShadowResourceBundleinstance(java.lang.String baseName, java.util.Locale locale)Deprecated.This method does not work correctly in dynamically loaded jars.protected static ShadowResourceBundleinstance(java.lang.String baseName, java.util.Locale locale, java.util.ResourceBundle bundle)Returns the instance of thebaseNameresource bundle for the given locale.static voidsetThreadLocale(java.util.Locale locale)Sets the locale for the current thread.
-
-
-
Constructor Detail
-
ShadowResourceBundle
protected ShadowResourceBundle() throws java.io.IOExceptionCreates aShadowResourceBundle, and reads resources from a.propertiesfile with the same name as the current class. For example, if the class is calledfoo.MyResource_en_US, reads fromfoo/MyResource_en_US.properties, thenfoo/MyResource_en.properties, thenfoo/MyResource.properties.- Throws:
java.io.IOException
-
-
Method Detail
-
getKeys
public java.util.Enumeration getKeys()
- Specified by:
getKeysin classjava.util.ResourceBundle
-
handleGetObject
protected java.lang.Object handleGetObject(java.lang.String key) throws java.util.MissingResourceException- Specified by:
handleGetObjectin classjava.util.ResourceBundle- Throws:
java.util.MissingResourceException
-
instance
protected static java.util.ResourceBundle instance(java.lang.String baseName)
Deprecated.This method does not work correctly in dynamically loaded jars.Returns the instance of thebaseNameresource bundle for the current thread's locale. For example, if called with "mondrian.olap.MondrianResource", from a thread which has calledsetThreadLocale(java.util.Locale)(Locale.FRENCH), will get an instance of "mondrian.olap.MondrianResource_FR" from the cache.This method should be called from a derived class, with the proper casting:
class MyResource extends ShadowResourceBundle { ... /** * Retrieves the instance of {@link MyResource} appropriate * to the current locale. If this thread has specified a locale * by calling {@link #setThreadLocale}, this locale is used, * otherwise the default locale is used. **/ public static MyResource instance() { return (MyResource) instance(MyResource.class.getName()); } ... }
-
instance
protected static ShadowResourceBundle instance(java.lang.String baseName, java.util.Locale locale)
Deprecated.This method does not work correctly in dynamically loaded jars.Returns the instance of thebaseNameresource bundle for the given locale.This method should be called from a derived class, with the proper casting:
class MyResource extends ShadowResourceBundle { ... /** * Retrieves the instance of {@link MyResource} appropriate * to the given locale. **/ public static MyResource instance(Locale locale) { return (MyResource) instance(MyResource.class.getName(), locale); } ... }
-
instance
protected static ShadowResourceBundle instance(java.lang.String baseName, java.util.Locale locale, java.util.ResourceBundle bundle)
Returns the instance of thebaseNameresource bundle for the given locale.This method should be called from a derived class, with the proper casting:
class MyResource extends ShadowResourceBundle { ... /** * Retrieves the instance of {@link MyResource} appropriate * to the given locale. **/ public static MyResource instance(Locale locale) { return (MyResource) instance( MyResource.class.getName(), locale, ResourceBundle.getBundle(MyResource.class.getName(), locale)); } ... }
-
getThreadOrDefaultLocale
protected static java.util.Locale getThreadOrDefaultLocale()
Returns the preferred locale of the current thread, or the default locale if the current thread has not calledsetThreadLocale(java.util.Locale).
-
setThreadLocale
public static void setThreadLocale(java.util.Locale locale)
Sets the locale for the current thread. Used byinstance(String,Locale).
-
getThreadLocale
public static java.util.Locale getThreadLocale()
Returns the preferred locale of the current thread, or null if the thread has not calledsetThreadLocale(java.util.Locale).
-
-