|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.ResourceBundle
org.eigenbase.resgen.ShadowResourceBundle
public abstract class ShadowResourceBundle
ShadowResourceBundle is an abstract base class for
ShadowResourceBundle.MyPropertyResourceBundle classes 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 ShadowResourceBundle.MyPropertyResourceBundle),
if you call ,
it first looks for a class called ResourceBundle.getBundle(java.lang.String)("foo.MyResource")foo.MyResource, then
looks for a file called foo/MyResource.properties. If it finds
the file, it creates a ShadowResourceBundle.MyPropertyResourceBundle and loads the class.
The problem is if you want to load the .properties file
into a dedicated class; ShadowResourceBundle helps with this
case.
You should create a class as follows:
package foo;
class MyResource extends org.eigenbase.resgen.ShadowResourceBundle {
public MyResource() throws java.io.IOException {
}
}
Then when you call
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 | |
|---|---|
(package private) static class |
ShadowResourceBundle.MyPropertyResourceBundle
|
| Nested classes/interfaces inherited from class java.util.ResourceBundle |
|---|
java.util.ResourceBundle.Control |
| Field Summary | |
|---|---|
protected static java.lang.Object[] |
emptyObjectArray
|
| Fields inherited from class java.util.ResourceBundle |
|---|
parent |
| Constructor Summary | |
|---|---|
protected |
ShadowResourceBundle()
Creates a ShadowResourceBundle, and reads resources from
a .properties file with the same name as the current class. |
| Method Summary | |
|---|---|
java.util.Enumeration |
getKeys()
|
static java.util.Locale |
getThreadLocale()
Returns the preferred locale of the current thread, or null if the thread has not called setThreadLocale(java.util.Locale). |
protected static java.util.Locale |
getThreadOrDefaultLocale()
Returns the preferred locale of the current thread, or the default locale if the current thread has not called setThreadLocale(java.util.Locale). |
protected java.lang.Object |
handleGetObject(java.lang.String key)
|
protected static java.util.ResourceBundle |
instance(java.lang.String baseName)
Deprecated. This method does not work correctly in dynamically loaded jars. |
protected static ShadowResourceBundle |
instance(java.lang.String baseName,
java.util.Locale locale)
Deprecated. This method does not work correctly in dynamically loaded jars. |
protected static ShadowResourceBundle |
instance(java.lang.String baseName,
java.util.Locale locale,
java.util.ResourceBundle bundle)
Returns the instance of the baseName resource bundle
for the given locale. |
static void |
setThreadLocale(java.util.Locale locale)
Sets the locale for the current thread. |
| Methods inherited from class java.util.ResourceBundle |
|---|
clearCache, clearCache, containsKey, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, handleKeySet, keySet, setParent |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final java.lang.Object[] emptyObjectArray
| Constructor Detail |
|---|
protected ShadowResourceBundle()
throws java.io.IOException
ShadowResourceBundle, and reads resources from
a .properties file with the same name as the current class.
For example, if the class is called foo.MyResource_en_US,
reads from foo/MyResource_en_US.properties, then
foo/MyResource_en.properties, then
foo/MyResource.properties.
java.io.IOException| Method Detail |
|---|
public java.util.Enumeration getKeys()
getKeys in class java.util.ResourceBundle
protected java.lang.Object handleGetObject(java.lang.String key)
throws java.util.MissingResourceException
handleGetObject in class java.util.ResourceBundlejava.util.MissingResourceExceptionprotected static java.util.ResourceBundle instance(java.lang.String baseName)
baseName resource bundle for
the current thread's locale. For example, if called with
"mondrian.olap.MondrianResource", from a thread which has called setThreadLocale(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());
}
...
}
protected static ShadowResourceBundle instance(java.lang.String baseName,
java.util.Locale locale)
baseName resource 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);
}
...
}
protected static ShadowResourceBundle instance(java.lang.String baseName,
java.util.Locale locale,
java.util.ResourceBundle bundle)
baseName resource 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));
}
...
}
protected static java.util.Locale getThreadOrDefaultLocale()
setThreadLocale(java.util.Locale).
public static void setThreadLocale(java.util.Locale locale)
instance(String,Locale).
public static java.util.Locale getThreadLocale()
setThreadLocale(java.util.Locale).
|
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||