ResourceBundle.Control 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
ResourceBundle.Control 定義套件組合載入程式期間由 Factory 方法叫 ResourceBundle#getBundle(String,
Locale, ClassLoader, Control) ResourceBundle.getBundle 用的一組回呼方法。
[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
- 繼承
- 屬性
備註
ResourceBundle.Control 定義套件組合載入程式期間由 Factory 方法叫 ResourceBundle#getBundle(String, Locale, ClassLoader, Control) ResourceBundle.getBundle 用的一組回呼方法。 換句話說,會 ResourceBundle.Control 與處理站方法來載入資源組合共同作業。 回呼方法的預設實作會提供處理站方法執行預設行為所需的資訊。
除了回呼方法之外, #toBundleName(String, Locale) toBundleName 和 #toResourceName(String, String) toResourceName 方法主要是為了方便實作回呼方法而定義。 不過, toBundleName 可以覆寫 方法,以在組織和封裝本地化資源時提供不同的慣例。 方法是toResourceNamefinal避免使用錯誤的資源和類別名稱分隔符。
和兩個處理站方法 #getControl(List) #getNoFallbackControl(List)提供 ResourceBundle.Control 實作預設套件組合載入程式常見變化的實例。
方法所 Control#getFormats(String) getFormats 傳回的格式和 方法所傳回 ResourceBundle.Control#getCandidateLocales(String, Locale) getCandidateLocales 的候選地區設定,在相同基底組合的所有 ResourceBundle.getBundle 調用中都必須一致。 否則, ResourceBundle.getBundle 方法可能會傳回非預期的套件組合。 例如,如果只有 "java.class" 方法傳 getFormats 回第一次呼叫 ResourceBundle.getBundle ,而只 "java.properties" 傳回第二次呼叫,則第二個呼叫會傳回在第一次呼叫期間快取的類別型呼叫。
ResourceBundle.Control如果實例同時供多個線程使用,則必須是安全線程。 ResourceBundle.getBundle 不會同步處理以呼叫 ResourceBundle.Control 方法。 方法的預設實作是安全線程。
應用程式可以指定 ResourceBundle.Control Factory 方法所 getControl 傳回的實例,或從的 ResourceBundle.Control 子類別建立,以自定義套件組合載入程式。 以下是變更預設套件組合載入程式的範例。
<b>範例 1</b>
下列程式代碼只允許 ResourceBundle.getBundle 查閱以屬性為基礎的資源。
import java.util.*;
import static java.util.ResourceBundle.Control.*;
...
ResourceBundle bundle =
ResourceBundle.getBundle("MyResources", new Locale("fr", "CH"),
ResourceBundle.Control.getControl(FORMAT_PROPERTIES));
在描述的範例ResourceBundle.getBundle中指定資源配套,此ResourceBundle.getBundle呼叫會載入MyResources_fr_CH.properties其父系為 MyResources_fr.properties 的父系。MyResources.properties (MyResources_fr_CH.properties 不是隱藏的,而是 MyResources_fr_CH.class 。
<b>範例 2</b>
以下是使用 Properties#loadFromXML(java.io.InputStream) Properties.loadFromXML載入 XML 型套件組合的範例。
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() {
...
}
}
已在1.6中新增。
的 java.util.ResourceBundle.ControlJava 檔。
此頁面的部分是根據 Android 開放原始碼專案所建立和共用的工作進行修改,並根據 Creative Commons 2.5 屬性授權中所述的詞彙使用。
建構函式
| ResourceBundle.Control() |
唯一的建構函式。 |
| ResourceBundle.Control(IntPtr, JniHandleOwnership) |
建立 JNI 物件的 Managed 表示法時使用的建構函式;由運行時間呼叫。 |
欄位
| TtlDontCache |
不快取已載入之資源配套實例的存留時間常數。 |
| TtlNoExpirationControl |
停用快取中已載入之資源套件組合實例到期控制的存留時間常數。 |
屬性
| Class |
傳回這個 |
| FormatClass |
包含 |
| FormatDefault |
預設格式 |
| FormatProperties |
僅包含 |
| Handle |
基礎Android實例的句柄。 (繼承來源 Object) |
| JniIdentityHashCode |
|
| JniPeerMembers |
|
| PeerReference |
|
| ThresholdClass |
此 API 支援適用於 Android 的 Mono 基礎結構,並不適合直接從您的程式代碼使用。 |
| ThresholdType |
此 API 支援適用於 Android 的 Mono 基礎結構,並不適合直接從您的程式代碼使用。 |
方法
| Clone() |
建立並傳回這個 對象的複本。 (繼承來源 Object) |
| Dispose() |
|
| Dispose(Boolean) |
|
| Equals(Object) |
指出其他物件是否「等於」這個物件。 (繼承來源 Object) |
| GetCandidateLocales(String, Locale) |
以 |
| GetControl(IList<String>) |
|
| GetFallbackLocale(String, Locale) |
傳 |
| GetFormats(String) |
傳回 的 |
| GetHashCode() |
傳回此物件的雜湊碼值。 (繼承來源 Object) |
| GetNoFallbackControl(IList<String>) |
|
| GetTimeToLive(String, Locale) |
針對在此 |
| JavaFinalize() |
當垃圾收集決定不再參考物件時,垃圾收集行程在 物件上呼叫。 (繼承來源 Object) |
| NeedsReload(String, Locale, String, ClassLoader, ResourceBundle, Int64) |
判斷快取中過期 |
| NewBundle(String, Locale, String, ClassLoader, Boolean) |
視需要使用指定的類別載入器,具現化指定格式和地區設定之指定套件組合名稱的資源配套。 |
| Notify() |
喚醒正在等候此物件監視器的單一線程。 (繼承來源 Object) |
| NotifyAll() |
喚醒正在等候此物件監視器的所有線程。 (繼承來源 Object) |
| SetHandle(IntPtr, JniHandleOwnership) |
設定 Handle 屬性。 (繼承來源 Object) |
| ToArray<T>() |
|
| ToBundleName(String, Locale) |
將指定的 |
| ToResourceName(String, String) |
指定的 |
| ToString() |
傳回物件的字串表示。 (繼承來源 Object) |
| UnregisterFromRuntime() |
|
| Wait() |
讓目前線程等候直到喚醒為止,通常是藉由em <notified/em>或<em>interrupted</em> 來喚醒它。<> (繼承來源 Object) |
| Wait(Int64, Int32) |
讓目前的線程等到喚醒為止,通常是因為 <em>notified</em> 或 <em>interrupted</em>,或直到經過一定數量的實時為止。 (繼承來源 Object) |
| Wait(Int64) |
讓目前的線程等到喚醒為止,通常是因為 <em>notified</em> 或 <em>interrupted</em>,或直到經過一定數量的實時為止。 (繼承來源 Object) |
明確介面實作
| IJavaPeerable.Disposed() |
|
| IJavaPeerable.DisposeUnlessReferenced() |
|
| IJavaPeerable.Finalized() |
|
| IJavaPeerable.JniManagedPeerState |
|
| IJavaPeerable.SetJniIdentityHashCode(Int32) |
|
| IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) |
|
| IJavaPeerable.SetPeerReference(JniObjectReference) |
|
擴充方法
| JavaCast<TResult>(IJavaObject) |
執行 Android 執行時間檢查的類型轉換。 |
| JavaCast<TResult>(IJavaObject) |
|
| GetJniTypeName(IJavaPeerable) |
|