public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSource implements BeanClassLoaderAware
MessageSource 実装。このクラスは、MessageFormatSE が提供する JDK の標準メッセージ解析と組み合わせて、基礎となる JDK の ResourceBundleSE 実装に依存しています。 この MessageSource は、アクセスされた ResourceBundle インスタンスと、各メッセージの生成された MessageFormats の両方をキャッシュします。また、AbstractMessageSource 基本クラスでサポートされているように、MessageFormat なしの引数なしメッセージのレンダリングも実装します。この MessageSource によって提供されるキャッシュは、java.util.ResourceBundle クラスの組み込みキャッシュよりも大幅に高速です。
ベース名は ResourceBundleSE の規則に従います。基本的に、完全修飾クラスパスの場所です。パッケージ修飾子(org.mypackage など)が含まれていない場合は、クラスパスルートから解決されます。JDK の標準 ResourceBundle は、ドットをパッケージ区切り文字として扱うことに注意してください。これは、"test.theme" が事実上「テスト / テーマ」と同等であることを意味します。
クラスパスでは、バンドルリソースはローカルに構成された encoding で読み取られます。デフォルトでは ISO-8859-1 です。これを UTF-8 に切り替えるか、プラットフォームのデフォルトエンコーディングを null に切り替えることを検討してください。ローカルで提供される ResourceBundle.Control ハンドルがサポートされていない JDK9 + モジュールパスでは、この MessageSource は常にプラットフォームのデフォルトエンコーディングで ResourceBundle.getBundle(java.lang.String)SE 取得にフォールバックします: JDK 9+ で ISO-8859-1 フォールバックを使用する UTF-8("java.util.PropertyResourceBundle.encoding" を介して構成可能)システムプロパティ)。この場合も loadBundle(Reader)/loadBundle(InputStream) は呼び出されず、サブクラスのオーバーライドは事実上無視されることに注意してください。代わりに、JDK 9 java.util.spi.ResourceBundleProvider の実装を検討してください。
AbstractResourceBasedMessageSource.setBasenames(java.lang.String...), ReloadableResourceBundleMessageSource, ResourceBundleSE, MessageFormatSElogger| コンストラクターと説明 |
|---|
ResourceBundleMessageSource() |
| 修飾子と型 | メソッドと説明 |
|---|---|
protected ResourceBundleSE | doGetBundle(StringSE basename, LocaleSE locale) 指定されたベース名とロケールのリソースバンドルを取得します。 |
protected ClassLoaderSE | getBundleClassLoader() リソースバンドルをロードする ClassLoader を返します。 |
protected MessageFormatSE | getMessageFormat(ResourceBundleSE bundle, StringSE code, LocaleSE locale) 指定されたバンドルとコードの MessageFormat を返し、すでに生成された MessageFormats をキャッシュから取得します。 |
protected ResourceBundleSE | getResourceBundle(StringSE basename, LocaleSE locale) 指定されたベース名とロケールの ResourceBundle を返し、すでに生成された ResourceBundle をキャッシュからフェッチします。 |
protected StringSE | getStringOrNull(ResourceBundleSE bundle, StringSE key) 指定されたキーの文字列値を効率的に取得します。見つからない場合は null を返します。 |
protected ResourceBundleSE | loadBundle(InputStreamSE inputStream) 指定された入力ストリームからプロパティベースのリソースバンドルをロードし、JDK 9 以降でデフォルトのプロパティエンコーディングを選択します。 |
protected ResourceBundleSE | loadBundle(ReaderSE reader) 指定されたリーダーからプロパティベースのリソースバンドルをロードします。 |
protected MessageFormatSE | resolveCode(StringSE code, LocaleSE locale) キャッシュされた MessageFormat インスタンスをメッセージコードごとに使用して、登録されたリソースバンドルのキーとして指定されたメッセージコードを解決します。 |
protected StringSE | resolveCodeWithoutArguments(StringSE code, LocaleSE locale) 登録されたリソースバンドルのキーとして指定されたメッセージコードを解決し、バンドルで見つかった値をそのまま(MessageFormat 解析なしで)返します。 |
void | setBeanClassLoader(ClassLoaderSE classLoader)Bean class loaderSE を Bean インスタンスに提供するコールバック。 |
void | setBundleClassLoader(ClassLoaderSE classLoader) リソースバンドルを読み込む ClassLoader を設定します。 |
StringSE | toString() この MessageSource の構成を表示します。 |
addBasenames, getBasenameSet, getCacheMillis, getDefaultEncoding, getDefaultLocale, isFallbackToSystemLocale, setBasename, setBasenames, setCacheMillis, setCacheSeconds, setDefaultEncoding, setDefaultLocale, setFallbackToSystemLocalegetCommonMessages, getDefaultMessage, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, resolveArguments, setCommonMessages, setParentMessageSource, setUseCodeAsDefaultMessagecreateMessageFormat, formatMessage, isAlwaysUseMessageFormat, renderDefaultMessage, setAlwaysUseMessageFormatcloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, waitSE, waitSE, waitSEpublic void setBundleClassLoader(ClassLoaderSE classLoader)
デフォルトは BeanFactory の bean ClassLoader を含むか、BeanFactory 内で実行されていない場合は ClassUtils.getDefaultClassLoader() によって決定されるデフォルト ClassLoader です。
@Nullable protected ClassLoaderSE getBundleClassLoader()
デフォルトは、BeanFactory の Bean ClassLoader を含んでいます。
public void setBeanClassLoader(ClassLoaderSE classLoader)
BeanClassLoaderAwareclass loaderSE を Bean インスタンスに提供するコールバック。 通常の Bean プロパティの設定後、ただし InitializingBean's InitializingBean.afterPropertiesSet() メソッドやカスタム init-method などの初期化コールバックの前に呼び出されます。
BeanClassLoaderAware の setBeanClassLoader classLoader - 所有クラスローダー protected StringSE resolveCodeWithoutArguments(StringSE code, LocaleSE locale)
AbstractMessageSource の resolveCodeWithoutArguments code - 解決するメッセージのコード locale - コードを解決するロケール (サブクラスは国際化をサポートすることが推奨されます)null AbstractMessageSource.resolveCode(java.lang.String, java.util.Locale), MessageFormatSE@Nullable protected MessageFormatSE resolveCode(StringSE code, LocaleSE locale)
AbstractMessageSource の resolveCode code - 解決するメッセージのコード locale - コードを解決するロケール (サブクラスは国際化をサポートすることが推奨されます)null AbstractMessageSource.resolveCodeWithoutArguments(String, java.util.Locale)@Nullable protected ResourceBundleSE getResourceBundle(StringSE basename, LocaleSE locale)
basename - ResourceBundle のベース名 locale - ResourceBundle を見つけるためのロケール null protected ResourceBundleSE doGetBundle(StringSE basename, LocaleSE locale) throws MissingResourceExceptionSE
basename - 検索するベース名 locale - 検索するロケール MissingResourceExceptionSE - 一致するバンドルが見つからなかった場合 ResourceBundle.getBundle(String, Locale, ClassLoader)SE, getBundleClassLoader()protected ResourceBundleSE loadBundle(ReaderSE reader) throws IOExceptionSE
これは、ResourceBundleMessageSource のデフォルトの ISO-8859-1 エンコーディングを含む "defaultEncoding" の場合に呼び出されます。このメソッドは ResourceBundle.Control でのみ呼び出すことができます。このようなコントロールハンドルがサポートされていない JDK 9+ モジュールパスで実行する場合、カスタムサブクラスのオーバーライドは事実上無視されます。
デフォルトの実装は PropertyResourceBundleSE を返します。
reader - ターゲットリソースのリーダー IOExceptionSE - I/O 障害の場合 loadBundle(InputStream), PropertyResourceBundle(Reader)SEprotected ResourceBundleSE loadBundle(InputStreamSE inputStream) throws IOExceptionSE
これは、"defaultEncoding" が null に設定されている場合にのみ呼び出され、プラットフォームのデフォルトエンコーディング(JDK 9+ で ISO-8859-1 フォールバックを備えた UTF-8 ですが、"java.util.PropertyResourceBundle.encoding" システムプロパティを介して構成可能)を明示的に適用します。このメソッドは ResourceBundle.Control でのみ呼び出すことができることに注意してください。このような制御ハンドルがサポートされていない JDK9 + モジュールパスで実行すると、カスタムサブクラスのオーバーライドは事実上無視されます。
デフォルトの実装は PropertyResourceBundleSE を返します。
inputStream - ターゲットリソースの入力ストリーム IOExceptionSE - I/O 障害の場合 loadBundle(Reader), PropertyResourceBundle(InputStream)SE@Nullable protected MessageFormatSE getMessageFormat(ResourceBundleSE bundle, StringSE code, LocaleSE locale) throws MissingResourceExceptionSE
bundle - ResourceBundle に取り組む code - 取得するメッセージコード locale - MessageFormat の構築に使用するロケール null MissingResourceExceptionSE - ResourceBundle によってスローされた場合 @Nullable protected StringSE getStringOrNull(ResourceBundleSE bundle, StringSE key)
null を返します。4.2 の時点で、デフォルトの実装は containsKey をチェックしてから getString を呼び出します(キーが見つからない場合は MissingResourceException をキャッチする必要があります)。
サブクラスでオーバーライドできます。
bundle - ResourceBundle で検索を実行します key - 見上げる鍵 null ResourceBundle.getString(String)SE, ResourceBundle.containsKey(String)SEpublic StringSE toString()
ObjectSE の toStringSE