// If this object does not care about language switching, we don't care either
if (languages.size() == 0)
return language;
// Remember the current language
Language original = currentLanguage;
// If the language is available, then simply select it
if (supportsLanguage(language)) {
currentLanguage = language;
}
// If the language is forced but not available, then throw an exception
else if (force) {
throw new IllegalStateException(this + " is not localized to " + language.getLocale().getDisplayLanguage());
}
// The selected language is not available. Use the original language instead
else if (behavior.equals(Original)) {
if (getOriginalLanguage() != null)
currentLanguage = getOriginalLanguage();
else if (languages.size() > 0)
throw new IllegalStateException("Language resolution failed for " + this);
}
// The selected language is not available. Use the default language instead
else if (behavior.equals(Default)) {
if (getDefaultLanguage() != null)
currentLanguage = getDefaultLanguage();
}
// Check the resolution process outcome
if (currentLanguage == null && languages.size() > 0)
throw new IllegalStateException("Language resolution failed for " + this);
// Notify interested parties
if (original == null || !original.equals(currentLanguage)) {
fireLanguageChanged(currentLanguage, language);
}
return currentLanguage;
}