ResourceBundle.Control Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
ResourceBundle.Control
defines a set of callback methods
that are invoked by the ResourceBundle#getBundle(String,
Locale, ClassLoader, Control) ResourceBundle.getBundle
factory
methods during the bundle loading process.
[Android.Runtime.Register("java/util/ResourceBundle$Control", DoNotGenerateAcw=true)]
public class ResourceBundle.Control : Java.Lang.Object
[<Android.Runtime.Register("java/util/ResourceBundle$Control", DoNotGenerateAcw=true)>]
type ResourceBundle.Control = class
inherit Object
- Inheritance
- Attributes
Remarks
ResourceBundle.Control
defines a set of callback methods that are invoked by the ResourceBundle#getBundle(String, Locale, ClassLoader, Control) ResourceBundle.getBundle
factory methods during the bundle loading process. In other words, a ResourceBundle.Control
collaborates with the factory methods for loading resource bundles. The default implementation of the callback methods provides the information necessary for the factory methods to perform the default behavior.
In addition to the callback methods, the #toBundleName(String, Locale) toBundleName
and #toResourceName(String, String) toResourceName
methods are defined primarily for convenience in implementing the callback methods. However, the toBundleName
method could be overridden to provide different conventions in the organization and packaging of localized resources. The toResourceName
method is final
to avoid use of wrong resource and class name separators.
Two factory methods, #getControl(List)
and #getNoFallbackControl(List)
, provide ResourceBundle.Control
instances that implement common variations of the default bundle loading process.
The formats returned by the Control#getFormats(String) getFormats
method and candidate locales returned by the ResourceBundle.Control#getCandidateLocales(String, Locale) getCandidateLocales
method must be consistent in all ResourceBundle.getBundle
invocations for the same base bundle. Otherwise, the ResourceBundle.getBundle
methods may return unintended bundles. For example, if only "java.class"
is returned by the getFormats
method for the first call to ResourceBundle.getBundle
and only "java.properties"
for the second call, then the second call will return the class-based one that has been cached during the first call.
A ResourceBundle.Control
instance must be thread-safe if it's simultaneously used by multiple threads. ResourceBundle.getBundle
does not synchronize to call the ResourceBundle.Control
methods. The default implementations of the methods are thread-safe.
Applications can specify ResourceBundle.Control
instances returned by the getControl
factory methods or created from a subclass of ResourceBundle.Control
to customize the bundle loading process. The following are examples of changing the default bundle loading process.
<b>Example 1</b>
The following code lets ResourceBundle.getBundle
look up only properties-based resources.
import java.util.*;
import static java.util.ResourceBundle.Control.*;
...
ResourceBundle bundle =
ResourceBundle.getBundle("MyResources", new Locale("fr", "CH"),
ResourceBundle.Control.getControl(FORMAT_PROPERTIES));
Given the resource bundles in the example in the ResourceBundle.getBundle
description, this ResourceBundle.getBundle
call loads MyResources_fr_CH.properties
whose parent is MyResources_fr.properties
whose parent is MyResources.properties
. (MyResources_fr_CH.properties
is not hidden, but MyResources_fr_CH.class
is.)
<b>Example 2</b>
The following is an example of loading XML-based bundles using Properties#loadFromXML(java.io.InputStream) Properties.loadFromXML
.
ResourceBundle rb = ResourceBundle.getBundle("Messages",
new ResourceBundle.Control() {
public List<String> getFormats(String baseName) {
if (baseName == null)
throw new NullPointerException();
return Arrays.asList("xml");
}
public ResourceBundle newBundle(String baseName,
Locale locale,
String format,
ClassLoader loader,
boolean reload)
throws IllegalAccessException,
InstantiationException,
IOException {
if (baseName == null || locale == null
|| format == null || loader == null)
throw new NullPointerException();
ResourceBundle bundle = null;
if (format.equals("xml")) {
String bundleName = toBundleName(baseName, locale);
String resourceName = toResourceName(bundleName, format);
InputStream stream = null;
if (reload) {
URL url = loader.getResource(resourceName);
if (url != null) {
URLConnection connection = url.openConnection();
if (connection != null) {
// Disable caches to get fresh data for
// reloading.
connection.setUseCaches(false);
stream = connection.getInputStream();
}
}
} else {
stream = loader.getResourceAsStream(resourceName);
}
if (stream != null) {
BufferedInputStream bis = new BufferedInputStream(stream);
bundle = new XMLResourceBundle(bis);
bis.close();
}
}
return bundle;
}
});
...
private static class XMLResourceBundle extends ResourceBundle {
private Properties props;
XMLResourceBundle(InputStream stream) throws IOException {
props = new Properties();
props.loadFromXML(stream);
}
protected Object handleGetObject(String key) {
return props.getProperty(key);
}
public Enumeration<String> getKeys() {
...
}
}
Added in 1.6.
Java documentation for java.util.ResourceBundle.Control
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
ResourceBundle.Control() |
Sole constructor. |
ResourceBundle.Control(IntPtr, JniHandleOwnership) |
A constructor used when creating managed representations of JNI objects; called by the runtime. |
Fields
TtlDontCache |
The time-to-live constant for not caching loaded resource bundle instances. |
TtlNoExpirationControl |
The time-to-live constant for disabling the expiration control for loaded resource bundle instances in the cache. |
Properties
Class |
Returns the runtime class of this |
FormatClass |
The class-only format |
FormatDefault |
The default format |
FormatProperties |
The properties-only format |
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
PeerReference | (Inherited from Object) |
ThresholdClass |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. |
ThresholdType |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. |
Methods
Clone() |
Creates and returns a copy of this object. (Inherited from Object) |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
GetCandidateLocales(String, Locale) |
Returns a |
GetControl(IList<String>) | |
GetFallbackLocale(String, Locale) |
Returns a |
GetFormats(String) |
Returns a |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
GetNoFallbackControl(IList<String>) | |
GetTimeToLive(String, Locale) |
Returns the time-to-live (TTL) value for resource bundles that
are loaded under this
|
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
NeedsReload(String, Locale, String, ClassLoader, ResourceBundle, Int64) |
Determines if the expired |
NewBundle(String, Locale, String, ClassLoader, Boolean) |
Instantiates a resource bundle for the given bundle name of the given format and locale, using the given class loader if necessary. |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
ToArray<T>() | (Inherited from Object) |
ToBundleName(String, Locale) |
Converts the given |
ToResourceName(String, String) |
Converts the given |
ToString() |
Returns a string representation of the object. (Inherited from Object) |
UnregisterFromRuntime() | (Inherited from Object) |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Explicit Interface Implementations
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |